@@ -87,11 +87,15 @@ let notifyPage = () => {
8787}
8888
8989var queryingCanScript = false ;
90- var caps = { } ;
90+
91+ function reload ( noCache = false ) {
92+ init = ( ) => { } ;
93+ location . reload ( noCache ) ;
94+ }
9195
9296async function init ( oldPage = false ) {
9397 if ( queryingCanScript ) return ;
94- if ( document . URL === "about:blank" ) {
98+ if ( ! document . URL . startsWith ( "http" ) ) {
9599 return ;
96100 }
97101 queryingCanScript = true ;
@@ -105,20 +109,21 @@ async function init(oldPage = false) {
105109 if ( canScript ) {
106110 if ( oldPage ) {
107111 probe ( ) ;
108- setTimeout ( ( ) => init ( ) , 100 ) ;
112+ setTimeout ( ( ) => init ( ) , 200 ) ;
109113 return ;
110114 }
111115 if ( ! shouldScript ) {
112116 // Something wrong: scripts can run, permissions say they shouldn't.
113117 // Was webRequest bypassed by caching/session restore/service workers?
118+ window . stop ( ) ;
114119 let noCache = ! ! navigator . serviceWorker . controller ;
115120 if ( noCache ) {
116121 for ( let r of await navigator . serviceWorker . getRegistrations ( ) ) {
117122 await r . unregister ( ) ;
118123 }
119124 }
120125 debug ( "Reloading %s (%s)" , document . URL , noCache ? "no cache" : "cached" ) ;
121- location . reload ( noCache ) ;
126+ reload ( noCache ) ;
122127 return ;
123128 }
124129 }
@@ -129,7 +134,8 @@ async function init(oldPage = false) {
129134 if ( ! oldPage &&
130135 / R e c e i v i n g e n d d o e s n o t e x i s t / . test ( e . message ) ) {
131136 // probably startup and bg page not ready yet, hence no CSP: reload!
132- location . reload ( false ) ;
137+ debug ( "Reloading" , document . URL ) ;
138+ reload ( ) ;
133139 } else {
134140 setTimeout ( ( ) => init ( oldPage ) , 100 ) ;
135141 }
@@ -162,4 +168,4 @@ async function init(oldPage = false) {
162168 // document.write("<plaintext>");
163169 }
164170 notifyPage ( ) || addEventListener ( "pageshow" , notifyPage ) ;
165- } ;
171+ }
0 commit comments