feat(News): refactor news service and add sentiment tracking

This commit is contained in:
2026-08-09 21:01:41 +02:00
parent 605e41cfeb
commit aff831cf58
390 changed files with 115094 additions and 9 deletions
@@ -0,0 +1,93 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.BidiDeserializer = void 0;
/**
* @license
* Copyright 2024 Google Inc.
* Modifications copyright (c) Microsoft Corporation.
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable object-curly-spacing */
/**
* @internal
*/
class BidiDeserializer {
static deserialize(result) {
var _result$value, _result$value2, _result$value3, _result$value4;
if (!result) return undefined;
switch (result.type) {
case 'array':
return (_result$value = result.value) === null || _result$value === void 0 ? void 0 : _result$value.map(value => {
return BidiDeserializer.deserialize(value);
});
case 'set':
return (_result$value2 = result.value) === null || _result$value2 === void 0 ? void 0 : _result$value2.reduce((acc, value) => {
return acc.add(BidiDeserializer.deserialize(value));
}, new Set());
case 'object':
return (_result$value3 = result.value) === null || _result$value3 === void 0 ? void 0 : _result$value3.reduce((acc, tuple) => {
const {
key,
value
} = BidiDeserializer._deserializeTuple(tuple);
acc[key] = value;
return acc;
}, {});
case 'map':
return (_result$value4 = result.value) === null || _result$value4 === void 0 ? void 0 : _result$value4.reduce((acc, tuple) => {
const {
key,
value
} = BidiDeserializer._deserializeTuple(tuple);
return acc.set(key, value);
}, new Map());
case 'promise':
return {};
case 'regexp':
return new RegExp(result.value.pattern, result.value.flags);
case 'date':
return new Date(result.value);
case 'undefined':
return undefined;
case 'null':
return null;
case 'number':
return BidiDeserializer._deserializeNumber(result.value);
case 'bigint':
return BigInt(result.value);
case 'boolean':
return Boolean(result.value);
case 'string':
return result.value;
}
throw new Error(`Deserialization of type ${result.type} not supported.`);
}
static _deserializeNumber(value) {
switch (value) {
case '-0':
return -0;
case 'NaN':
return NaN;
case 'Infinity':
return Infinity;
case '-Infinity':
return -Infinity;
default:
return value;
}
}
static _deserializeTuple([serializedKey, serializedValue]) {
const key = typeof serializedKey === 'string' ? serializedKey : BidiDeserializer.deserialize(serializedKey);
const value = BidiDeserializer.deserialize(serializedValue);
return {
key,
value
};
}
}
exports.BidiDeserializer = BidiDeserializer;
@@ -0,0 +1,238 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBidiKeyValue = void 0;
/**
* @license
* Copyright 2024 Google Inc.
* Modifications copyright (c) Microsoft Corporation.
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable curly */
const getBidiKeyValue = key => {
switch (key) {
case '\r':
case '\n':
key = 'Enter';
break;
}
// Measures the number of code points rather than UTF-16 code units.
if ([...key].length === 1) {
return key;
}
switch (key) {
case 'Cancel':
return '\uE001';
case 'Help':
return '\uE002';
case 'Backspace':
return '\uE003';
case 'Tab':
return '\uE004';
case 'Clear':
return '\uE005';
case 'Enter':
return '\uE007';
case 'Shift':
case 'ShiftLeft':
return '\uE008';
case 'Control':
case 'ControlLeft':
return '\uE009';
case 'Alt':
case 'AltLeft':
return '\uE00A';
case 'Pause':
return '\uE00B';
case 'Escape':
return '\uE00C';
case 'PageUp':
return '\uE00E';
case 'PageDown':
return '\uE00F';
case 'End':
return '\uE010';
case 'Home':
return '\uE011';
case 'ArrowLeft':
return '\uE012';
case 'ArrowUp':
return '\uE013';
case 'ArrowRight':
return '\uE014';
case 'ArrowDown':
return '\uE015';
case 'Insert':
return '\uE016';
case 'Delete':
return '\uE017';
case 'NumpadEqual':
return '\uE019';
case 'Numpad0':
return '\uE01A';
case 'Numpad1':
return '\uE01B';
case 'Numpad2':
return '\uE01C';
case 'Numpad3':
return '\uE01D';
case 'Numpad4':
return '\uE01E';
case 'Numpad5':
return '\uE01F';
case 'Numpad6':
return '\uE020';
case 'Numpad7':
return '\uE021';
case 'Numpad8':
return '\uE022';
case 'Numpad9':
return '\uE023';
case 'NumpadMultiply':
return '\uE024';
case 'NumpadAdd':
return '\uE025';
case 'NumpadSubtract':
return '\uE027';
case 'NumpadDecimal':
return '\uE028';
case 'NumpadDivide':
return '\uE029';
case 'F1':
return '\uE031';
case 'F2':
return '\uE032';
case 'F3':
return '\uE033';
case 'F4':
return '\uE034';
case 'F5':
return '\uE035';
case 'F6':
return '\uE036';
case 'F7':
return '\uE037';
case 'F8':
return '\uE038';
case 'F9':
return '\uE039';
case 'F10':
return '\uE03A';
case 'F11':
return '\uE03B';
case 'F12':
return '\uE03C';
case 'Meta':
case 'MetaLeft':
return '\uE03D';
case 'ShiftRight':
return '\uE050';
case 'ControlRight':
return '\uE051';
case 'AltRight':
return '\uE052';
case 'MetaRight':
return '\uE053';
case 'Digit0':
return '0';
case 'Digit1':
return '1';
case 'Digit2':
return '2';
case 'Digit3':
return '3';
case 'Digit4':
return '4';
case 'Digit5':
return '5';
case 'Digit6':
return '6';
case 'Digit7':
return '7';
case 'Digit8':
return '8';
case 'Digit9':
return '9';
case 'KeyA':
return 'a';
case 'KeyB':
return 'b';
case 'KeyC':
return 'c';
case 'KeyD':
return 'd';
case 'KeyE':
return 'e';
case 'KeyF':
return 'f';
case 'KeyG':
return 'g';
case 'KeyH':
return 'h';
case 'KeyI':
return 'i';
case 'KeyJ':
return 'j';
case 'KeyK':
return 'k';
case 'KeyL':
return 'l';
case 'KeyM':
return 'm';
case 'KeyN':
return 'n';
case 'KeyO':
return 'o';
case 'KeyP':
return 'p';
case 'KeyQ':
return 'q';
case 'KeyR':
return 'r';
case 'KeyS':
return 's';
case 'KeyT':
return 't';
case 'KeyU':
return 'u';
case 'KeyV':
return 'v';
case 'KeyW':
return 'w';
case 'KeyX':
return 'x';
case 'KeyY':
return 'y';
case 'KeyZ':
return 'z';
case 'Semicolon':
return ';';
case 'Equal':
return '=';
case 'Comma':
return ',';
case 'Minus':
return '-';
case 'Period':
return '.';
case 'Slash':
return '/';
case 'Backquote':
return '`';
case 'BracketLeft':
return '[';
case 'Backslash':
return '\\';
case 'BracketRight':
return ']';
case 'Quote':
return '"';
default:
throw new Error(`Unknown key: "${key}"`);
}
};
exports.getBidiKeyValue = getBidiKeyValue;
@@ -0,0 +1,139 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.Storage = exports.Session = exports.Script = exports.Network = exports.Log = exports.Input = exports.ErrorCode = exports.BrowsingContext = exports.Browser = void 0;
/**
* @license
* Copyright 2024 Google Inc.
* Modifications copyright (c) Microsoft Corporation.
* SPDX-License-Identifier: Apache-2.0
*/
/**
* THIS FILE IS AUTOGENERATED by cddlconv 0.1.5.
* Run `node tools/generate-bidi-types.mjs` to regenerate.
* @see https://github.com/w3c/webdriver-bidi/blob/master/index.bs
*/
/**
* Must be between `-9007199254740991` and `9007199254740991`, inclusive.
*/
/**
* Must be between `0` and `9007199254740991`, inclusive.
*/
let ErrorCode = exports.ErrorCode = /*#__PURE__*/function (ErrorCode) {
ErrorCode["InvalidArgument"] = "invalid argument";
ErrorCode["InvalidSelector"] = "invalid selector";
ErrorCode["InvalidSessionId"] = "invalid session id";
ErrorCode["MoveTargetOutOfBounds"] = "move target out of bounds";
ErrorCode["NoSuchAlert"] = "no such alert";
ErrorCode["NoSuchElement"] = "no such element";
ErrorCode["NoSuchFrame"] = "no such frame";
ErrorCode["NoSuchHandle"] = "no such handle";
ErrorCode["NoSuchHistoryEntry"] = "no such history entry";
ErrorCode["NoSuchIntercept"] = "no such intercept";
ErrorCode["NoSuchNode"] = "no such node";
ErrorCode["NoSuchRequest"] = "no such request";
ErrorCode["NoSuchScript"] = "no such script";
ErrorCode["NoSuchStoragePartition"] = "no such storage partition";
ErrorCode["NoSuchUserContext"] = "no such user context";
ErrorCode["SessionNotCreated"] = "session not created";
ErrorCode["UnableToCaptureScreen"] = "unable to capture screen";
ErrorCode["UnableToCloseBrowser"] = "unable to close browser";
ErrorCode["UnableToSetCookie"] = "unable to set cookie";
ErrorCode["UnableToSetFileInput"] = "unable to set file input";
ErrorCode["UnderspecifiedStoragePartition"] = "underspecified storage partition";
ErrorCode["UnknownCommand"] = "unknown command";
ErrorCode["UnknownError"] = "unknown error";
ErrorCode["UnsupportedOperation"] = "unsupported operation";
return ErrorCode;
}({});
let Session = exports.Session = void 0;
(function (_Session10) {
let UserPromptHandlerType = /*#__PURE__*/function (UserPromptHandlerType) {
UserPromptHandlerType["Accept"] = "accept";
UserPromptHandlerType["Dismiss"] = "dismiss";
UserPromptHandlerType["Ignore"] = "ignore";
return UserPromptHandlerType;
}({});
_Session10.UserPromptHandlerType = UserPromptHandlerType;
})(Session || (exports.Session = Session = {}));
let Browser = exports.Browser = void 0;
let BrowsingContext = exports.BrowsingContext = void 0;
(function (_BrowsingContext10) {
let ReadinessState = /*#__PURE__*/function (ReadinessState) {
ReadinessState["None"] = "none";
ReadinessState["Interactive"] = "interactive";
ReadinessState["Complete"] = "complete";
return ReadinessState;
}({});
_BrowsingContext10.ReadinessState = ReadinessState;
})(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
(function (_BrowsingContext11) {
let UserPromptType = /*#__PURE__*/function (UserPromptType) {
UserPromptType["Alert"] = "alert";
UserPromptType["Beforeunload"] = "beforeunload";
UserPromptType["Confirm"] = "confirm";
UserPromptType["Prompt"] = "prompt";
return UserPromptType;
}({});
_BrowsingContext11.UserPromptType = UserPromptType;
})(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
(function (_BrowsingContext24) {
let CreateType = /*#__PURE__*/function (CreateType) {
CreateType["Tab"] = "tab";
CreateType["Window"] = "window";
return CreateType;
}({});
_BrowsingContext24.CreateType = CreateType;
})(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
let Network = exports.Network = void 0;
(function (_Network6) {
let SameSite = /*#__PURE__*/function (SameSite) {
SameSite["Strict"] = "strict";
SameSite["Lax"] = "lax";
SameSite["None"] = "none";
return SameSite;
}({});
_Network6.SameSite = SameSite;
})(Network || (exports.Network = Network = {}));
(function (_Network23) {
let InterceptPhase = /*#__PURE__*/function (InterceptPhase) {
InterceptPhase["BeforeRequestSent"] = "beforeRequestSent";
InterceptPhase["ResponseStarted"] = "responseStarted";
InterceptPhase["AuthRequired"] = "authRequired";
return InterceptPhase;
}({});
_Network23.InterceptPhase = InterceptPhase;
})(Network || (exports.Network = Network = {}));
let Script = exports.Script = void 0;
(function (_Script68) {
let ResultOwnership = /*#__PURE__*/function (ResultOwnership) {
ResultOwnership["Root"] = "root";
ResultOwnership["None"] = "none";
return ResultOwnership;
}({});
_Script68.ResultOwnership = ResultOwnership;
})(Script || (exports.Script = Script = {}));
let Storage = exports.Storage = void 0;
let Log = exports.Log = void 0;
(function (_Log7) {
let Level = /*#__PURE__*/function (Level) {
Level["Debug"] = "debug";
Level["Info"] = "info";
Level["Warn"] = "warn";
Level["Error"] = "error";
return Level;
}({});
_Log7.Level = Level;
})(Log || (exports.Log = Log = {}));
let Input = exports.Input = void 0;
(function (_Input9) {
let PointerType = /*#__PURE__*/function (PointerType) {
PointerType["Mouse"] = "mouse";
PointerType["Pen"] = "pen";
PointerType["Touch"] = "touch";
return PointerType;
}({});
_Input9.PointerType = PointerType;
})(Input || (exports.Input = Input = {}));
@@ -0,0 +1,144 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isRegExp = exports.isPlainObject = exports.isDate = exports.BidiSerializer = void 0;
/**
* @license
* Copyright 2024 Google Inc.
* Modifications copyright (c) Microsoft Corporation.
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable curly, indent */
/**
* @internal
*/
class UnserializableError extends Error {}
/**
* @internal
*/
class BidiSerializer {
static serialize(arg) {
switch (typeof arg) {
case 'symbol':
case 'function':
throw new UnserializableError(`Unable to serializable ${typeof arg}`);
case 'object':
return BidiSerializer._serializeObject(arg);
case 'undefined':
return {
type: 'undefined'
};
case 'number':
return BidiSerializer._serializeNumber(arg);
case 'bigint':
return {
type: 'bigint',
value: arg.toString()
};
case 'string':
return {
type: 'string',
value: arg
};
case 'boolean':
return {
type: 'boolean',
value: arg
};
}
}
static _serializeNumber(arg) {
let value;
if (Object.is(arg, -0)) {
value = '-0';
} else if (Object.is(arg, Infinity)) {
value = 'Infinity';
} else if (Object.is(arg, -Infinity)) {
value = '-Infinity';
} else if (Object.is(arg, NaN)) {
value = 'NaN';
} else {
value = arg;
}
return {
type: 'number',
value
};
}
static _serializeObject(arg) {
if (arg === null) {
return {
type: 'null'
};
} else if (Array.isArray(arg)) {
const parsedArray = arg.map(subArg => {
return BidiSerializer.serialize(subArg);
});
return {
type: 'array',
value: parsedArray
};
} else if (isPlainObject(arg)) {
try {
JSON.stringify(arg);
} catch (error) {
if (error instanceof TypeError && error.message.startsWith('Converting circular structure to JSON')) {
error.message += ' Recursive objects are not allowed.';
}
throw error;
}
const parsedObject = [];
for (const key in arg) {
parsedObject.push([BidiSerializer.serialize(key), BidiSerializer.serialize(arg[key])]);
}
return {
type: 'object',
value: parsedObject
};
} else if (isRegExp(arg)) {
return {
type: 'regexp',
value: {
pattern: arg.source,
flags: arg.flags
}
};
} else if (isDate(arg)) {
return {
type: 'date',
value: arg.toISOString()
};
}
throw new UnserializableError('Custom object serialization not possible. Use plain objects instead.');
}
}
/**
* @internal
*/
exports.BidiSerializer = BidiSerializer;
const isPlainObject = obj => {
return typeof obj === 'object' && (obj === null || obj === void 0 ? void 0 : obj.constructor) === Object;
};
/**
* @internal
*/
exports.isPlainObject = isPlainObject;
const isRegExp = obj => {
return typeof obj === 'object' && (obj === null || obj === void 0 ? void 0 : obj.constructor) === RegExp;
};
/**
* @internal
*/
exports.isRegExp = isRegExp;
const isDate = obj => {
return typeof obj === 'object' && (obj === null || obj === void 0 ? void 0 : obj.constructor) === Date;
};
exports.isDate = isDate;
@@ -0,0 +1,221 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.createProfile = createProfile;
var _fs = _interopRequireDefault(require("fs"));
var _path = _interopRequireDefault(require("path"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* @license
* Copyright 2023 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
/* eslint-disable curly, indent */
async function createProfile(options) {
if (!_fs.default.existsSync(options.path)) {
await _fs.default.promises.mkdir(options.path, {
recursive: true
});
}
await writePreferences({
preferences: {
...defaultProfilePreferences(options.preferences),
...options.preferences
},
path: options.path
});
}
function defaultProfilePreferences(extraPrefs) {
const server = 'dummy.test';
const defaultPrefs = {
// Make sure Shield doesn't hit the network.
'app.normandy.api_url': '',
// Disable Firefox old build background check
'app.update.checkInstallTime': false,
// Disable automatically upgrading Firefox
'app.update.disabledForTesting': true,
// Increase the APZ content response timeout to 1 minute
'apz.content_response_timeout': 60000,
// Prevent various error message on the console
// jest-puppeteer asserts that no error message is emitted by the console
'browser.contentblocking.features.standard': '-tp,tpPrivate,cookieBehavior0,-cm,-fp',
// Enable the dump function: which sends messages to the system
// console
// https://bugzilla.mozilla.org/show_bug.cgi?id=1543115
'browser.dom.window.dump.enabled': true,
// Disable topstories
'browser.newtabpage.activity-stream.feeds.system.topstories': false,
// Always display a blank page
'browser.newtabpage.enabled': false,
// Background thumbnails in particular cause grief: and disabling
// thumbnails in general cannot hurt
'browser.pagethumbnails.capturing_disabled': true,
// Disable safebrowsing components.
'browser.safebrowsing.blockedURIs.enabled': false,
'browser.safebrowsing.downloads.enabled': false,
'browser.safebrowsing.malware.enabled': false,
'browser.safebrowsing.phishing.enabled': false,
// Disable updates to search engines.
'browser.search.update': false,
// Do not restore the last open set of tabs if the browser has crashed
'browser.sessionstore.resume_from_crash': false,
// Skip check for default browser on startup
'browser.shell.checkDefaultBrowser': false,
// Disable newtabpage
'browser.startup.homepage': 'about:blank',
// Do not redirect user when a milstone upgrade of Firefox is detected
'browser.startup.homepage_override.mstone': 'ignore',
// Start with a blank page about:blank
'browser.startup.page': 0,
// Do not allow background tabs to be zombified on Android: otherwise for
// tests that open additional tabs: the test harness tab itself might get
// unloaded
'browser.tabs.disableBackgroundZombification': false,
// Do not warn when closing all other open tabs
'browser.tabs.warnOnCloseOtherTabs': false,
// Do not warn when multiple tabs will be opened
'browser.tabs.warnOnOpen': false,
// Do not automatically offer translations, as tests do not expect this.
'browser.translations.automaticallyPopup': false,
// Disable the UI tour.
'browser.uitour.enabled': false,
// Turn off search suggestions in the location bar so as not to trigger
// network connections.
'browser.urlbar.suggest.searches': false,
// Disable first run splash page on Windows 10
'browser.usedOnWindows10.introURL': '',
// Do not warn on quitting Firefox
'browser.warnOnQuit': false,
// Defensively disable data reporting systems
'datareporting.healthreport.documentServerURI': `http://${server}/dummy/healthreport/`,
'datareporting.healthreport.logging.consoleEnabled': false,
'datareporting.healthreport.service.enabled': false,
'datareporting.healthreport.service.firstRun': false,
'datareporting.healthreport.uploadEnabled': false,
// Do not show datareporting policy notifications which can interfere with tests
'datareporting.policy.dataSubmissionEnabled': false,
'datareporting.policy.dataSubmissionPolicyBypassNotification': true,
// DevTools JSONViewer sometimes fails to load dependencies with its require.js.
// This doesn't affect Puppeteer but spams console (Bug 1424372)
'devtools.jsonview.enabled': false,
// Disable popup-blocker
'dom.disable_open_during_load': false,
// Enable the support for File object creation in the content process
// Required for |Page.setFileInputFiles| protocol method.
'dom.file.createInChild': true,
// Disable the ProcessHangMonitor
'dom.ipc.reportProcessHangs': false,
// Disable slow script dialogues
'dom.max_chrome_script_run_time': 0,
'dom.max_script_run_time': 0,
// Only load extensions from the application and user profile
// AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
'extensions.autoDisableScopes': 0,
'extensions.enabledScopes': 5,
// Disable metadata caching for installed add-ons by default
'extensions.getAddons.cache.enabled': false,
// Disable installing any distribution extensions or add-ons.
'extensions.installDistroAddons': false,
// Disabled screenshots extension
'extensions.screenshots.disabled': true,
// Turn off extension updates so they do not bother tests
'extensions.update.enabled': false,
// Turn off extension updates so they do not bother tests
'extensions.update.notifyUser': false,
// Make sure opening about:addons will not hit the network
'extensions.webservice.discoverURL': `http://${server}/dummy/discoveryURL`,
// Allow the application to have focus even it runs in the background
'focusmanager.testmode': true,
// Disable useragent updates
'general.useragent.updates.enabled': false,
// Always use network provider for geolocation tests so we bypass the
// macOS dialog raised by the corelocation provider
'geo.provider.testing': true,
// Do not scan Wifi
'geo.wifi.scan': false,
// No hang monitor
'hangmonitor.timeout': 0,
// Show chrome errors and warnings in the error console
'javascript.options.showInConsole': true,
// Disable download and usage of OpenH264: and Widevine plugins
'media.gmp-manager.updateEnabled': false,
// Disable the GFX sanity window
'media.sanity-test.disabled': true,
// Disable experimental feature that is only available in Nightly
'network.cookie.sameSite.laxByDefault': false,
// Do not prompt for temporary redirects
'network.http.prompt-temp-redirect': false,
// Disable speculative connections so they are not reported as leaking
// when they are hanging around
'network.http.speculative-parallel-limit': 0,
// Do not automatically switch between offline and online
'network.manage-offline-status': false,
// Make sure SNTP requests do not hit the network
'network.sntp.pools': server,
// Disable Flash.
'plugin.state.flash': 0,
'privacy.trackingprotection.enabled': false,
// Can be removed once Firefox 89 is no longer supported
// https://bugzilla.mozilla.org/show_bug.cgi?id=1710839
'remote.enabled': true,
// Don't do network connections for mitm priming
'security.certerrors.mitm.priming.enabled': false,
// Local documents have access to all other local documents,
// including directory listings
'security.fileuri.strict_origin_policy': false,
// Do not wait for the notification button security delay
'security.notification_enable_delay': 0,
// Ensure blocklist updates do not hit the network
'services.settings.server': `http://${server}/dummy/blocklist/`,
// Do not automatically fill sign-in forms with known usernames and
// passwords
'signon.autofillForms': false,
// Disable password capture, so that tests that include forms are not
// influenced by the presence of the persistent doorhanger notification
'signon.rememberSignons': false,
// Disable first-run welcome page
'startup.homepage_welcome_url': 'about:blank',
// Disable first-run welcome page
'startup.homepage_welcome_url.additional': '',
// Disable browser animations (tabs, fullscreen, sliding alerts)
'toolkit.cosmeticAnimations.enabled': false,
// Prevent starting into safe mode after application crashes
'toolkit.startup.max_resumed_crashes': -1
};
return Object.assign(defaultPrefs, extraPrefs);
}
/**
* Populates the user.js file with custom preferences as needed to allow
* Firefox's CDP 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) {
const prefsPath = _path.default.join(options.path, 'prefs.js');
const lines = Object.entries(options.preferences).map(([key, value]) => {
return `user_pref(${JSON.stringify(key)}, ${JSON.stringify(value)});`;
});
// Use allSettled to prevent corruption
const result = await Promise.allSettled([_fs.default.promises.writeFile(_path.default.join(options.path, 'user.js'), lines.join('\n')),
// Create a backup of the preferences file if it already exitsts.
_fs.default.promises.access(prefsPath, _fs.default.constants.F_OK).then(async () => {
await _fs.default.promises.copyFile(prefsPath, _path.default.join(options.path, 'prefs.js.playwright'));
},
// Swallow only if file does not exist
() => {})]);
for (const command of result) {
if (command.status === 'rejected') {
throw command.reason;
}
}
}