Skip to content

Commit 5b585a4

Browse files
committed
verbose setting, silence all logging unless verbose, misc fixes
1 parent 832fa93 commit 5b585a4

File tree

5 files changed

+70
-24
lines changed

5 files changed

+70
-24
lines changed

src/background.js

Lines changed: 57 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3256
async function initCurrentContext () {
3357
if (currentContext) {
@@ -123,7 +147,7 @@ let lastDetailsForTabId = {};
123147
function 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 () {
279302
function 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
}
300336
BROWSER.webRequest.onBeforeRequest.addListener(webRequest_onBeforeRequest, {
301337
urls: [

src/component.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ exports.for = function (ctx) {
124124
ctx.browser.runtime.sendMessage({
125125
to: "broadcast",
126126
event: "currentContext"
127+
}).catch(function (err) {
128+
if (/Receiving end does not exist/.test(err.message)) {
129+
// Silence error as it is expected once in the beginning.
130+
// TODO: Make establishing a connection more deterministic so we do not need to slicence any errors.
131+
// TODO: Display error when in dev mode.
132+
return;
133+
}
134+
// TODO: Only log when in dev mode.
135+
console.error('WARNING: Error while broadcasting current context:', err.message);
127136
});
128137
}, 250);
129138

src/console.rep.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ console.log("CLEAR lastRequestConsole CONSOLE!!");
179179

180180
//console.log("APPEND MESSAGE TO REQUEST CONSOLE");
181181

182-
console.log("LOG TO CONSOLE 1", message.message);
182+
//console.log("LOG TO CONSOLE 1", message.message);
183183
message.message.meta = (
184184
message.message.meta &&
185185
JSON.parse(message.message.meta)

src/layout.rep.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ exports.main = function (JSONREP, node, options) {
219219
});
220220

221221
comp.on("message", function (message) {
222-
console.log("message in layout", message);
222+
//console.log("message in layout", message);
223223
if (message.event === "manage") {
224224
forceManage = true;
225225
sync();
@@ -230,7 +230,7 @@ console.log("message in layout", message);
230230
} else {
231231
forceEditor = true;
232232
}
233-
console.log("forceEditor in layout", forceEditor);
233+
//console.log("forceEditor in layout", forceEditor);
234234
sync();
235235
}
236236
});

src/settings.rep.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exports.main = function (JSONREP, node, options) {
1616

1717
<ul>
1818
<li><input type="checkbox" name="reloadOnEnable" scope="global" onchange={syncCheckbox}/> Reload page on <b>Enable</b></li>
19+
<li><input type="checkbox" name="verbose" scope="global" onchange={syncCheckbox}/> Enable internal extension logging for debugging purposes</li>
1920
</ul>
2021

2122
<h2>Settings for: { hostname }</h2>

0 commit comments

Comments
 (0)