@@ -20,7 +20,7 @@ const contentScriptsToInject = IS_FIREFOX
2020 js : [ 'build/proxy.js' ] ,
2121 matches : [ '<all_urls>' ] ,
2222 persistAcrossSessions : true ,
23- runAt : 'document_end ' ,
23+ runAt : 'document_idle ' ,
2424 world : chrome . scripting . ExecutionWorld . ISOLATED ,
2525 } ,
2626 {
@@ -43,26 +43,19 @@ const contentScriptsToInject = IS_FIREFOX
4343
4444async function dynamicallyInjectContentScripts ( ) {
4545 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 ( ) ;
5550
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 ) ;
6659 } catch ( error ) {
6760 console . error ( error ) ;
6861 }
0 commit comments