Closed Bug 1559167 Opened 5 years ago Closed 5 years ago

Services.console.logMessage() does not log to web console

Categories

(DevTools :: Console, defect, P3)

69 Branch
defect

Tracking

(firefox70 fixed)

RESOLVED FIXED
Firefox 70
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.

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:

Hope this helps!

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?

Yes, that innerWindowID attribute comes from the content process.

Priority: -- → P3

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. :)

[1] https://searchfox.org/mozilla-central/rev/06bd14ced96f25ff1dbd5352cb985fc0fa12a64e/browser/base/content/browser-siteIdentity.js#421

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
See Also: → 1577478
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 70
See Also: → 1577767
Assignee: nobody → pbz
Regressions: 1743028
See Also: 1743028
You need to log in before you can comment on or make changes to this bug.