@puppeteer/browsers
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -154,3 +154,3 @@ "use strict"; | ||
} | ||
await writePreferences({ | ||
await syncPreferences({ | ||
preferences: { | ||
@@ -323,26 +323,27 @@ ...defaultProfilePreferences(options.preferences), | ||
} | ||
async function backupFile(input) { | ||
if (!fs_1.default.existsSync(input)) { | ||
return; | ||
} | ||
await fs_1.default.promises.copyFile(input, input + '.puppeteer'); | ||
} | ||
/** | ||
* Populates the user.js file with custom preferences as needed to allow | ||
* Firefox's CDP support to properly function. These preferences will be | ||
* Firefox's support to properly function. These preferences will be | ||
* automatically copied over to prefs.js during startup of Firefox. To be | ||
* able to restore the original values of preferences a backup of prefs.js | ||
* will be created. | ||
* | ||
* @param prefs - List of preferences to add. | ||
* @param profilePath - Firefox profile to write the preferences to. | ||
*/ | ||
async function writePreferences(options) { | ||
async function syncPreferences(options) { | ||
const prefsPath = path_1.default.join(options.path, 'prefs.js'); | ||
const userPath = path_1.default.join(options.path, 'user.js'); | ||
const lines = Object.entries(options.preferences).map(([key, value]) => { | ||
return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`; | ||
}); | ||
// Use allSettled to prevent corruption | ||
// 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 | ||
() => { }), | ||
backupFile(userPath).then(async () => { | ||
await fs_1.default.promises.writeFile(userPath, lines.join('\n')); | ||
}), | ||
backupFile(prefsPath), | ||
]); | ||
@@ -349,0 +350,0 @@ for (const command of result) { |
@@ -144,3 +144,3 @@ /** | ||
} | ||
await writePreferences({ | ||
await syncPreferences({ | ||
preferences: { | ||
@@ -312,26 +312,27 @@ ...defaultProfilePreferences(options.preferences), | ||
} | ||
async function backupFile(input) { | ||
if (!fs.existsSync(input)) { | ||
return; | ||
} | ||
await fs.promises.copyFile(input, input + '.puppeteer'); | ||
} | ||
/** | ||
* Populates the user.js file with custom preferences as needed to allow | ||
* Firefox's CDP support to properly function. These preferences will be | ||
* Firefox's support to properly function. These preferences will be | ||
* automatically copied over to prefs.js during startup of Firefox. To be | ||
* able to restore the original values of preferences a backup of prefs.js | ||
* will be created. | ||
* | ||
* @param prefs - List of preferences to add. | ||
* @param profilePath - Firefox profile to write the preferences to. | ||
*/ | ||
async function writePreferences(options) { | ||
async function syncPreferences(options) { | ||
const prefsPath = path.join(options.path, 'prefs.js'); | ||
const userPath = path.join(options.path, 'user.js'); | ||
const lines = Object.entries(options.preferences).map(([key, value]) => { | ||
return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`; | ||
}); | ||
// Use allSettled to prevent corruption | ||
// 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 | ||
() => { }), | ||
backupFile(userPath).then(async () => { | ||
await fs.promises.writeFile(userPath, lines.join('\n')); | ||
}), | ||
backupFile(prefsPath), | ||
]); | ||
@@ -338,0 +339,0 @@ for (const command of result) { |
{ | ||
"name": "@puppeteer/browsers", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "Download and launch browsers", | ||
@@ -98,3 +98,3 @@ "scripts": { | ||
"dependencies": { | ||
"debug": "^4.3.5", | ||
"debug": "^4.3.6", | ||
"extract-zip": "^2.0.1", | ||
@@ -101,0 +101,0 @@ "progress": "^2.0.3", |
@@ -175,3 +175,3 @@ /** | ||
} | ||
await writePreferences({ | ||
await syncPreferences({ | ||
preferences: { | ||
@@ -399,14 +399,20 @@ ...defaultProfilePreferences(options.preferences), | ||
async function backupFile(input: string): Promise<void> { | ||
if (!fs.existsSync(input)) { | ||
return; | ||
} | ||
await fs.promises.copyFile(input, input + '.puppeteer'); | ||
} | ||
/** | ||
* Populates the user.js file with custom preferences as needed to allow | ||
* Firefox's CDP support to properly function. These preferences will be | ||
* Firefox's support to properly function. These preferences will be | ||
* automatically copied over to prefs.js during startup of Firefox. To be | ||
* able to restore the original values of preferences a backup of prefs.js | ||
* will be created. | ||
* | ||
* @param prefs - List of preferences to add. | ||
* @param profilePath - Firefox profile to write the preferences to. | ||
*/ | ||
async function writePreferences(options: ProfileOptions): Promise<void> { | ||
async function syncPreferences(options: ProfileOptions): Promise<void> { | ||
const prefsPath = path.join(options.path, 'prefs.js'); | ||
const userPath = path.join(options.path, 'user.js'); | ||
const lines = Object.entries(options.preferences).map(([key, value]) => { | ||
@@ -416,16 +422,8 @@ return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`; | ||
// Use allSettled to prevent corruption | ||
// 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 | ||
() => {} | ||
), | ||
backupFile(userPath).then(async () => { | ||
await fs.promises.writeFile(userPath, lines.join('\n')); | ||
}), | ||
backupFile(prefsPath), | ||
]); | ||
@@ -432,0 +430,0 @@ for (const command of result) { |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
487238
8866
1
Updateddebug@^4.3.6