Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions packages/wxt/src/virtual/utils/reload-content-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,30 @@ export async function reloadManifestContentScriptMv3(
]);
} else {
logger.debug('Registering new content script...');
await browser.scripting.registerContentScripts([
{
...contentScript,
try {
await browser.scripting.registerContentScripts([
{
...contentScript,
id,
css: contentScript.css ?? [],
},
]);
} catch (err) {
// Two reload events for the same entrypoint can both read an empty
// registration above and both register; the loser throws "Duplicate
// script ID". The winner is registering this same script and reloads
// the tabs once it lands, so the loser has nothing left to do. It must
// not fall back to updateContentScripts (the winner's registration is
// not complete yet, so that throws "not fully registered") and must not
// reload tabs (they would come back before the script is registered).
const message = String((err as Error)?.message ?? err);
if (!message.includes('Duplicate script ID')) throw err;
logger.debug(
'Lost a registration race, the concurrent register owns it',
id,
css: contentScript.css ?? [],
},
]);
);
return;
}
}

await reloadTabsForContentScript(contentScript);
Expand Down