@@ -20,7 +20,7 @@ const contentScriptsToInject = IS_FIREFOX
20
20
js : [ 'build/proxy.js' ] ,
21
21
matches : [ '<all_urls>' ] ,
22
22
persistAcrossSessions : true ,
23
- runAt : 'document_end ' ,
23
+ runAt : 'document_idle ' ,
24
24
world : chrome . scripting . ExecutionWorld . ISOLATED ,
25
25
} ,
26
26
{
@@ -43,26 +43,19 @@ const contentScriptsToInject = IS_FIREFOX
43
43
44
44
async function dynamicallyInjectContentScripts ( ) {
45
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 ( ) ;
55
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 ) ;
66
59
} catch ( error ) {
67
60
console . error ( error ) ;
68
61
}
0 commit comments