@@ -28,6 +28,30 @@ wildfire.once("error", function (err) {
2828
2929
3030
31+ function syncDebugSetting ( ) {
32+ LIB . browser . storage . local . get ( 'verbose' ) . then ( function ( value ) {
33+ if ( typeof value . verbose === 'undefined' ) {
34+ LIB . browser . storage . local . set ( {
35+ verbose : false
36+ } ) . catch ( function ( ) { } ) ;
37+ } else
38+ if ( ! value . verbose || value . verbose === 'false' ) {
39+ wildfire . VERBOSE = false ;
40+ } else
41+ if ( value . verbose ) {
42+ wildfire . VERBOSE = true ;
43+ }
44+ } ) . catch ( function ( ) { } ) ;
45+ }
46+ syncDebugSetting ( ) ;
47+
48+ LIB . browser . storage . onChanged . addListener ( function ( changes , area ) {
49+ if ( typeof changes . verbose !== 'undefined' ) {
50+ syncDebugSetting ( ) ;
51+ }
52+ } ) ;
53+
54+
3155
3256async function initCurrentContext ( ) {
3357 if ( currentContext ) {
@@ -123,7 +147,7 @@ let lastDetailsForTabId = {};
123147function setCurrentContextFromDetails ( details , clearIfNew ) {
124148 if ( ! details ) {
125149 if ( currentContext ) {
126- console . log ( "CLEAR CONTEXT" , "reset serverUrl" ) ;
150+ if ( wildfire . VERBOSE ) console . log ( "CLEAR CONTEXT" , "reset serverUrl" ) ;
127151
128152 currentContext = null ;
129153 serverUrl = null ;
@@ -146,10 +170,10 @@ console.log("CLEAR CONTEXT", "reset serverUrl");
146170 newCtx . pageUid !== currentContext . pageUid
147171 )
148172 ) {
149- console . log ( "NEW CONTEXT" , "reset serverUrl" , currentContext , newCtx ) ;
173+ if ( wildfire . VERBOSE ) console . log ( "NEW CONTEXT" , "reset serverUrl" , currentContext , newCtx ) ;
150174 serverUrl = null ;
151175
152- // console.log("NEW CONTEXT", newCtx, details);
176+ if ( wildfire . VERBOSE ) console . log ( "NEW CONTEXT" , newCtx , details ) ;
153177
154178 currentContext = newCtx ;
155179 lastDetailsForTabId [ currentContext . tabId ] = details ;
@@ -164,7 +188,7 @@ console.log("NEW CONTEXT", "reset serverUrl", currentContext, newCtx);
164188 }
165189
166190 if ( clearIfNew ) {
167- // console.log("SEND PREPARE DUE TO NEW CONTEXT", details);
191+ if ( wildfire . VERBOSE ) console . log ( "SEND PREPARE DUE TO NEW CONTEXT" , details ) ;
168192 broadcastForContext ( currentContext , {
169193 event : "prepare"
170194 } ) ;
@@ -201,15 +225,14 @@ async function runtime_onMessage (message) {
201225 } else
202226 if ( message . event === "load-file" ) {
203227
204-
205- console . log ( "LOAD FILE FROM:::" , serverUrl ) ;
228+ if ( wildfire . VERBOSE ) console . log ( "LOAD FILE FROM:::" , serverUrl ) ;
206229
207230 const file = message . file ;
208231 const line = message . line ;
209232
210233 if ( ! serverUrl ) {
211234
212- console . log ( "SLIP LOAD FILE FROM::: DUE TO NO serverUrl" ) ;
235+ if ( wildfire . VERBOSE ) console . log ( "SLIP LOAD FILE FROM::: DUE TO NO serverUrl" ) ;
213236
214237 // TODO: Show error 'Server URL not available!' in UI
215238 return ;
@@ -224,7 +247,7 @@ console.log("SLIP LOAD FILE FROM::: DUE TO NO serverUrl");
224247 }
225248 } ) ;
226249
227- console . log ( "SERVER response:" , response ) ;
250+ if ( wildfire . VERBOSE ) console . log ( "SERVER response:" , response ) ;
228251
229252 if ( ! response ) {
230253 return ;
@@ -261,7 +284,7 @@ function webNavigation_onBeforeNavigate (details) {
261284 return ;
262285 }
263286
264- console . log ( "ON BEFORE NAVIGATE" , details ) ;
287+ if ( wildfire . VERBOSE ) console . log ( "ON BEFORE NAVIGATE" , details ) ;
265288
266289 setCurrentContextFromDetails ( details ) ;
267290}
@@ -279,23 +302,36 @@ wildfire.on("destroy", function () {
279302function webRequest_onBeforeRequest ( details ) {
280303 if ( wildfire . VERBOSE ) console . log ( "[background] BROWSER.webRequest -| onBeforeRequest (details):" , details ) ;
281304
282- // We only care about the page frame event.
305+ // We only care about the page frame event so we can reset the console .
283306 if (
284- (
285- // Firefox
286- typeof details . documentUrl !== "undefined" ||
287- // Google Chrome
288- typeof details . initiator !== "undefined"
289- ) ||
290- details . parentFrameId !== - 1
307+ // Works for FF & Chrome when reloading page.
308+ // LIMITATION: In Chrome, there is no way to distinguish between a reload, forward navigate or backward navigate
309+ // so the console will clear with back button where on FF the event does not fire so the
310+ // previous console content for the URL re-appears. This latter behaviour is desired.
311+ // TODO: Once Chrome provides property to determine type of navigation we can lift the limitation.
312+ details . type === "main_frame"
291313 ) {
292- // These are resource or sub-frame events
293- return ;
314+ if ( wildfire . VERBOSE ) console . log ( "ON BEFORE PAGE REQUEST (should clear console)" , details ) ;
315+
316+ setCurrentContextFromDetails ( details , true ) ;
294317 }
295318
296- console . log ( "ON BEFORE REQUEST" , details ) ;
319+ // if (
320+ // (
321+ // // Firefox
322+ // typeof details.documentUrl !== "undefined" ||
323+ // // Google Chrome
324+ // typeof details.initiator !== "undefined"
325+ // ) ||
326+ // details.parentFrameId !== -1
327+ // ) {
328+ // // These are resource or sub-frame events
329+ // return;
330+ // }
331+
332+ // console.log("ON BEFORE REQUEST", details);
297333
298- setCurrentContextFromDetails ( details , true ) ;
334+ // setCurrentContextFromDetails(details, true);
299335}
300336BROWSER . webRequest . onBeforeRequest . addListener ( webRequest_onBeforeRequest , {
301337 urls : [
0 commit comments