1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-10-22 11:22:43 +02: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,12 +132,27 @@ chrome.runtime.onMessage.addListener(() => {
* MAIN world injection does not work properly via manifest
* https://bugs.chromium.org/p/chromium/issues/detail?id=634381
*/
chrome.scripting.registerContentScripts([
{
id: 'inpage',
matches: ['file://*/*', 'http://*/*', 'https://*/*'],
js: ['inpage.js'],
runAt: 'document_start',
world: 'MAIN',
},
]);
const registerInPageContentScript = async () => {
try {
await chrome.scripting.registerContentScripts([
{
id: 'inpage',
matches: ['file://*/*', 'http://*/*', 'https://*/*'],
js: ['inpage.js'],
runAt: 'document_start',
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();