@puppeteer/browsers
Advanced tools
Comparing version
@@ -333,11 +333,20 @@ "use strict"; | ||
async function writePreferences(options) { | ||
const prefsPath = path_1.default.join(options.path, 'prefs.js'); | ||
const lines = Object.entries(options.preferences).map(([key, value]) => { | ||
return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`; | ||
}); | ||
await fs_1.default.promises.writeFile(path_1.default.join(options.path, 'user.js'), lines.join('\n')); | ||
// Create a backup of the preferences file if it already exitsts. | ||
const prefsPath = path_1.default.join(options.path, 'prefs.js'); | ||
if (fs_1.default.existsSync(prefsPath)) { | ||
const prefsBackupPath = path_1.default.join(options.path, 'prefs.js.puppeteer'); | ||
await fs_1.default.promises.copyFile(prefsPath, prefsBackupPath); | ||
// Use allSettled to prevent corruption | ||
const result = await Promise.allSettled([ | ||
fs_1.default.promises.writeFile(path_1.default.join(options.path, 'user.js'), lines.join('\n')), | ||
// Create a backup of the preferences file if it already exitsts. | ||
fs_1.default.promises.access(prefsPath, fs_1.default.constants.F_OK).then(async () => { | ||
await fs_1.default.promises.copyFile(prefsPath, path_1.default.join(options.path, 'prefs.js.puppeteer')); | ||
}, | ||
// Swallow only if file does not exist | ||
() => { }), | ||
]); | ||
for (const command of result) { | ||
if (command.status === 'rejected') { | ||
throw command.reason; | ||
} | ||
} | ||
@@ -344,0 +353,0 @@ } |
@@ -322,11 +322,20 @@ /** | ||
async function writePreferences(options) { | ||
const prefsPath = path.join(options.path, 'prefs.js'); | ||
const lines = Object.entries(options.preferences).map(([key, value]) => { | ||
return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`; | ||
}); | ||
await fs.promises.writeFile(path.join(options.path, 'user.js'), lines.join('\n')); | ||
// Create a backup of the preferences file if it already exitsts. | ||
const prefsPath = path.join(options.path, 'prefs.js'); | ||
if (fs.existsSync(prefsPath)) { | ||
const prefsBackupPath = path.join(options.path, 'prefs.js.puppeteer'); | ||
await fs.promises.copyFile(prefsPath, prefsBackupPath); | ||
// Use allSettled to prevent corruption | ||
const result = await Promise.allSettled([ | ||
fs.promises.writeFile(path.join(options.path, 'user.js'), lines.join('\n')), | ||
// Create a backup of the preferences file if it already exitsts. | ||
fs.promises.access(prefsPath, fs.constants.F_OK).then(async () => { | ||
await fs.promises.copyFile(prefsPath, path.join(options.path, 'prefs.js.puppeteer')); | ||
}, | ||
// Swallow only if file does not exist | ||
() => { }), | ||
]); | ||
for (const command of result) { | ||
if (command.status === 'rejected') { | ||
throw command.reason; | ||
} | ||
} | ||
@@ -333,0 +342,0 @@ } |
{ | ||
"name": "@puppeteer/browsers", | ||
"version": "2.2.2", | ||
"version": "2.2.3", | ||
"description": "Download and launch browsers", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -409,2 +409,3 @@ /** | ||
async function writePreferences(options: ProfileOptions): Promise<void> { | ||
const prefsPath = path.join(options.path, 'prefs.js'); | ||
const lines = Object.entries(options.preferences).map(([key, value]) => { | ||
@@ -414,12 +415,21 @@ return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`; | ||
await fs.promises.writeFile( | ||
path.join(options.path, 'user.js'), | ||
lines.join('\n') | ||
); | ||
// Create a backup of the preferences file if it already exitsts. | ||
const prefsPath = path.join(options.path, 'prefs.js'); | ||
if (fs.existsSync(prefsPath)) { | ||
const prefsBackupPath = path.join(options.path, 'prefs.js.puppeteer'); | ||
await fs.promises.copyFile(prefsPath, prefsBackupPath); | ||
// Use allSettled to prevent corruption | ||
const result = await Promise.allSettled([ | ||
fs.promises.writeFile(path.join(options.path, 'user.js'), lines.join('\n')), | ||
// Create a backup of the preferences file if it already exitsts. | ||
fs.promises.access(prefsPath, fs.constants.F_OK).then( | ||
async () => { | ||
await fs.promises.copyFile( | ||
prefsPath, | ||
path.join(options.path, 'prefs.js.puppeteer') | ||
); | ||
}, | ||
// Swallow only if file does not exist | ||
() => {} | ||
), | ||
]); | ||
for (const command of result) { | ||
if (command.status === 'rejected') { | ||
throw command.reason; | ||
} | ||
} | ||
@@ -426,0 +436,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
476214
0.3%8660
0.34%