console.log in content scripts does not print to the current tab's web console

RESOLVED FIXED

Status

defect
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: canuckistani, Assigned: mossop)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments, 1 obsolete attachment)

Workaround:

console = unsafeWindow.console

^ this feels problematic though, I wish we could intercept console.* in content scripts and send the output to the web console of a tab a content script is attached to.
Assignee: nobody → dtownsend+bugmail
This is probably straightforward once bug 993029 is done, or I might end up doing it as a part of that.
Depends on: 993029
Posted patch console API patch (obsolete) — Splinter Review
This allows us to create consoles for a specific window by passing an innerID option. It also makes the console API listener consistently use inner IDs for filtering messages.
Attachment #8406237 - Flags: review?(mihai.sucan)
Comment on attachment 8406237 [details] [diff] [review]
console API patch

Review of attachment 8406237 [details] [diff] [review]:
-----------------------------------------------------------------

LGTM.

Should we have tests for this?

::: toolkit/devtools/Console.jsm
@@ +518,5 @@
>   *        - groupName: for group(), groupCollapsed() and groupEnd().
>   *        - stacktrace: for trace(). Holds the array of stack frames as given by
>   *        getStack().
>   */
> +function sendConsoleAPIMessage(aConsole, aLevel, aFrame, aArgs, aOptions = {})

jsdoc needs to mention the new aConsole argument.

@@ +586,5 @@
>    // in order to avoid runtime checks on each console method call.
>    this.dump = aConsoleOptions.dump || dump;
>    this.prefix = aConsoleOptions.prefix || "";
>    this.maxLogLevel = aConsoleOptions.maxLogLevel || "all";
> +  this.innerID = aConsoleOptions.innerID || null;

Please update the list of options in the jsdoc.
Attachment #8406237 - Flags: review?(mihai.sucan) → review+
Fixed the comments and added a simple copy of the console API test.
Attachment #8406416 - Flags: review?(mihai.sucan)
Comment on attachment 8406416 [details] [diff] [review]
console API patch with tests

Review of attachment 8406416 [details] [diff] [review]:
-----------------------------------------------------------------

Thanks for the update. LGTM

::: toolkit/devtools/Console.jsm
@@ +524,2 @@
>   */
> +function sendConsoleAPIMessage(aConsole, aLevel, aFrame, aArgs, aOptions = {})

The jsdoc comment is still missing the new aConsole argument.
Attachment #8406416 - Flags: review?(mihai.sucan) → review+
Posted file Add-on SDK changes
These are the Add-on SDK changes
Attachment #8406237 - Attachment is obsolete: true
Attachment #8407062 - Flags: review?(rFobic)
Comment on attachment 8407062 [details] [review]
Add-on SDK changes

Looks good to me.
Attachment #8407062 - Flags: review?(rFobic) → review+
Commits pushed to master at https://github.com/mozilla/addon-sdk

https://github.com/mozilla/addon-sdk/commit/3a2e7f3e721c1feee2e92b1f34aa7638e22a885d
Bug 993520: Create a custom console for workers tagged with the inner window ID of the worker's DOM window.

https://github.com/mozilla/addon-sdk/commit/985284bb00d6cd5b4ca6335762686b62abe13612
Merge pull request #1458 from Mossop/bug993520

Bug 993520: Create a custom console for workers tagged with the inner window ID of the worker's DOM window. r=gozala
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Whiteboard: [leave open]
You need to log in before you can comment on or make changes to this bug.