11
js: ['build/proxy.js'],
12
matches: ['<all_urls>'],
13
persistAcrossSessions: true,
14
- runAt: 'document_idle',
14
+ runAt: 'document_end',
15
},
16
]
17
: [
43
44
async function dynamicallyInjectContentScripts() {
45
try {
46
- const alreadyRegisteredContentScripts =
47
- await chrome.scripting.getRegisteredContentScripts();
48
-
49
- const scriptsToInjectNow = contentScriptsToInject.filter(
50
- scriptToInject =>
51
- !alreadyRegisteredContentScripts.some(
52
- registeredScript => registeredScript.id === scriptToInject.id,
53
- ),
54
- );
46
+ // Using this, instead of filtering registered scrips with `chrome.scripting.getRegisteredScripts`
47
+ // because of https://bugs.chromium.org/p/chromium/issues/detail?id=1393762
48
+ // This fixes registering proxy content script in incognito mode
49
+ await chrome.scripting.unregisterContentScripts();
50
56
- if (scriptsToInjectNow.length) {
57
- // equivalent logic for Firefox is in prepareInjection.js
58
- // Manifest V3 method of injecting content script
59
- // TODO(hoxyq): migrate Firefox to V3 manifests
60
- // Note: the "world" option in registerContentScripts is only available in Chrome v102+
61
- // It's critical since it allows us to directly run scripts on the "main" world on the page
62
- // "document_start" allows it to run before the page's scripts
63
- // so the hook can be detected by react reconciler
64
- await chrome.scripting.registerContentScripts(scriptsToInjectNow);
65
- }
51
+ // equivalent logic for Firefox is in prepareInjection.js
52
+ // Manifest V3 method of injecting content script
53
+ // TODO(hoxyq): migrate Firefox to V3 manifests
54
+ // Note: the "world" option in registerContentScripts is only available in Chrome v102+
55
+ // It's critical since it allows us to directly run scripts on the "main" world on the page
56
+ // "document_start" allows it to run before the page's scripts
57
+ // so the hook can be detected by react reconciler
58
+ await chrome.scripting.registerContentScripts(contentScriptsToInject);
59
} catch (error) {
60
console.error(error);
61
}