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:
parent
a64f82e8a0
commit
a8189ba253
@ -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://*/*'],
|
||||||
@ -140,4 +142,17 @@ chrome.scripting.registerContentScripts([
|
|||||||
runAt: 'document_start',
|
runAt: 'document_start',
|
||||||
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();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user