Firefox gives an extension page in a private window locks of its own. A popup there could save between the background's read and its write of the stored record, and undo a network switch the background had saved. manifest/firefox.json now sets "incognito": "not_allowed", so a page in a private window cannot read or write extension storage. tests/manifest.test.js pins the key. The README says this in "Stored state and its version". Six code comments drop their private-window exception to the lock. docs/README.md tells Firefox users that AutistMask does not work in private windows. Model: opus-5-5
27 lines
1001 B
JavaScript
27 lines
1001 B
JavaScript
// `navigator.locks` for the unit tests, which run on node, where there is none.
|
|
//
|
|
// One lock per name: granted in the order it was asked for, and let go when
|
|
// the callback settles, whether it resolved or rejected. That is what the
|
|
// browser's own does for the one call the extension makes,
|
|
// `navigator.locks.request(name, callback)`. Every module a test file loads
|
|
// shares it, as the extension's background and its pages share the browser's
|
|
// (README, "Stored state and its version").
|
|
//
|
|
// Run before each test file by `setupFiles` in package.json.
|
|
|
|
// For each name, a promise that settles once the last request for it has
|
|
// let the lock go.
|
|
const released = new Map();
|
|
|
|
function request(name, callback) {
|
|
const previous = released.get(name) || Promise.resolve();
|
|
const result = previous.then(() => callback({ name, mode: "exclusive" }));
|
|
released.set(
|
|
name,
|
|
result.catch(() => {}),
|
|
);
|
|
return result;
|
|
}
|
|
|
|
globalThis.navigator = { locks: { request } };
|