Services.console.logMessage() does not log to web console
Categories
(DevTools :: Console, defect, P3)
Tracking
(firefox70 fixed)
Tracking | Status | |
---|---|---|
firefox70 | --- | fixed |
People
(Reporter: pbz, Assigned: pbz)
References
(Regressed 1 open bug)
Details
Attachments
(1 file)
I'm trying to log a message to the web-console like so:
let consoleMsg = Cc["@mozilla.org/scripterror;1"].createInstance(Ci.nsIScriptError);
let windowId = gBrowser.selectedBrowser.innerWindowID;
let message = "Hello, World!";
consoleMsg.initWithWindowID(message, gBrowser.currentURI.prePath, null, 0, 0,
Ci.nsIScriptError.warningFlag, "Test",
windowId);
Services.console.logMessage(consoleMsg);
from browser-fullScreenAndPointerLock.js.
The log message appears in the browser-console, but not in the web-console.
Comment 1•5 years ago
|
||
Hello Paul,
So we have this function in devtools to log messages into the console: devtools/server/actors/targets/browsing-context.js#669-677
And I must say it looks a lot like what you're doing.
My guess is that there's something wrong with the window id or the category?
So you can debug this by:
- Opening the webconsole
- Open the Browser Content Toolbox
- Set a breakpoint on this function devtools/server/actors/webconsole/listeners/console-service.js#70-81, and check that you don't hit one of the early return.
Hope this helps!
Assignee | ||
Comment 2•5 years ago
•
|
||
Hi Nicolas,
Thanks for looking into this!
The category doesn't seem to be an issue since any category that is not internal will be accepted: console-service.js#100.
The breakpoints I set in the Browser Content Toolbox don't get hit. However, in the Browser Toolbox I can see the logging statements i added to console-service.js
. This leads me to believe that either the window ID is incorrect or that it's not properly forwarding to the correct content process.
Say I want to log to the currently active tab, shouldn't gBrowser.selectedBrowser.innerWindowID
be the right window id?
Comment 3•5 years ago
|
||
Yes, that innerWindowID
attribute comes from the content process.
Updated•5 years ago
|
Comment 4•5 years ago
|
||
Paul and I sat and diagnosed this. The issue seems to be that Services.console.logMessage() doesn't work across process boundaries.
The following code snippet works in the browser content toolbox:
var console = Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService);
var scriptError = Cc["@mozilla.org/scripterror;1"].createInstance(Ci.nsIScriptError);
scriptError.initWithWindowID("foo", null, null, 0, 0, Ci.nsIScriptError.warningFlag, "bar", tabs[0].content.document.defaultView.windowUtils.currentInnerWindowID);
console.logMessage(scriptError);
and the following doesn't work in the main browser console:
var scriptError = Cc["@mozilla.org/scripterror;1"].createInstance(Ci.nsIScriptError);
scriptError.initWithWindowID("foo", null, null, 0, 0, Ci.nsIScriptError.warningFlag, "bar", gBrowser.selectedBrowser.innerWindowID);
Services.console.logMessage(scriptError);
where, we verified that the innerWindowIDs being passed in both cases are identical.
This is problematic because even if this is the intended behavior of this API, we are currently using it in browser chrome code to send logging to the Web console [1] and apparently we aren't aware that this doesn't actually work. I'm unsure if this is a regression, or if a false assumption was made. I'm also unsure if this is the only instance of this misuse (or regressed use) but I don't have time to dig into this more right now. :)
Assignee | ||
Comment 5•5 years ago
|
||
Pushed by pzuhlcke@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/720ff3a404a7 Updated logMessage to support logging of scriptErrors from parent to content process. r=baku
Comment 7•5 years ago
|
||
bugherder |
Comment 8•5 years ago
|
||
bugherder uplift |
Updated•5 years ago
|
Updated•2 years ago
|
Description
•