1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

MV3: catch "Duplicate script ID 'inpage'" error (#15973)

* sw: catch Duplicate script ID 'inpage' error
- related to #15958

* typo: cased -> caused
This commit is contained in:
Ariella Vu 2022-09-27 15:29:27 -03:00 committed by GitHub
parent a64f82e8a0
commit a8189ba253
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -132,7 +132,9 @@ chrome.runtime.onMessage.addListener(() => {
* MAIN world injection does not work properly via manifest * MAIN world injection does not work properly via manifest
* https://bugs.chromium.org/p/chromium/issues/detail?id=634381 * https://bugs.chromium.org/p/chromium/issues/detail?id=634381
*/ */
chrome.scripting.registerContentScripts([ const registerInPageContentScript = async () => {
try {
await chrome.scripting.registerContentScripts([
{ {
id: 'inpage', id: 'inpage',
matches: ['file://*/*', 'http://*/*', 'https://*/*'], matches: ['file://*/*', 'http://*/*', 'https://*/*'],
@ -141,3 +143,16 @@ chrome.scripting.registerContentScripts([
world: 'MAIN', world: 'MAIN',
}, },
]); ]);
} catch (err) {
/**
* An error occurs when app-init.js is reloaded. Attempts to avoid the duplicate script error:
* 1. registeringContentScripts inside runtime.onInstalled - This caused a race condition
* in which the provider might not be loaded in time.
* 2. await chrome.scripting.getRegisteredContentScripts() to check for an existing
* inpage script before registering - The provider is not loaded on time.
*/
console.warn(`Dropped attempt to register inpage content script. ${err}`);
}
};
registerInPageContentScript();