Open Bug 1433724 Opened 6 years ago Updated 10 months ago

Web Extension API to listen console log messages

Categories

(WebExtensions :: Developer Tools, enhancement, P5)

enhancement

Tracking

(Not tracked)

UNCONFIRMED

People

(Reporter: kabilan.vk, Unassigned)

References

Details

(Whiteboard: [design-decision-approved][dev-ux])

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36

Steps to reproduce:

Support to listen console messages using new browser extensions.
i.e. https://developer.mozilla.org/en-US/docs/Tools/Browser_Console


Actual results:

No support as of now.


Expected results:

Way to access console messages through extensions.
Severity: normal → enhancement
Component: Untriaged → WebExtensions: Untriaged
OS: Unspecified → All
Product: Firefox → Toolkit
Hardware: Unspecified → All
It helps streamline the decision-making progress for proposed new APIs if you can explain what sorts of extensions would use this API and how they would use it.
Flags: needinfo?(kabilan.vk)
Whiteboard: design-decision-needed
Component: WebExtensions: Untriaged → WebExtensions: Developer Tools
We are using the consoleexport (https://github.com/firebug/consoleexport) extension to download all console log messages for our QA automation testing purposes. ConsoleExport actually uses Firebug to listen console logs. When Firebug is deprecated by Firefox, we moved to this example (https://github.com/firebug/devtools-extension-examples/tree/master/ConsoleListener) posted in GitHub to achieve the same. The example used the console API as i mentioned in the bug description but that's gone now in Firefox Quantum. Can you please add console API support in new web-extensions framework?
Flags: needinfo?(kabilan.vk)
Product: Toolkit → WebExtensions
Priority: -- → P5
Whiteboard: design-decision-needed → [design-decision-approved]
Whiteboard: [design-decision-approved] → [design-decision-approved][dev-ux]
Severity: normal → S3

This is design-decision-approved but it's been a long time so I'll ask.

If I implemented this, would the patch be accepted? I'm imagining something like browser.devtools.console with events for each of the categories in devtools like onError, onWarning, onInfo, onDebug.

What do you think?

Flags: needinfo?(rob)

The request is to listen to console messages from a script. If those (onError, onWarning, onInfo, onDebug) APIs are supported for listening that's good.

(In reply to Gregory Pappas [:gregp] from comment #3)

This is design-decision-approved but it's been a long time so I'll ask.

If I implemented this, would the patch be accepted? I'm imagining something like browser.devtools.console with events for each of the categories in devtools like onError, onWarning, onInfo, onDebug.

What do you think?

Are there current use cases that cannot be addressed with the existing alternatives?

Automation tools can already use the CDP and subscribe to Runtime.consoleAPICalled messages. This was implemented in bug 1553854.
Firefox does not support the chrome.debugger API that enables extensions to connect through the CDP. But extensions can already intercept console.log, etc. calls by using a content script that override the console API. It is also possible to catch uncaught errors through the window.onerror and window.onunhandledrejection events.

Flags: needinfo?(rob)
See Also: → 1553854

Please note that we should no longer propose to use any CDP API with Firefox. Instead our WebDriver BiDi implementation should be utilized and listening for logs can easily be done by subscribing to the log.entryAdded event by using session.subscribe. This event supports both console API calls and Javascript errors.

Thanks for the suggestions, Rob and Henrik. Can you point me to an example code that uses "log.entryAdded" and "session.subscribe" events to listen to console messages?

Well, that was just a pointer to where we have it implemented. But for a WebExtension API it won't make sense to directly use this code. Instead a proper API dedicated for WebExtension would have to be agreed on and implemented. Nevertheless can you find the related code from Webdriver BiDi here: https://searchfox.org/mozilla-central/source/remote/webdriver-bidi/modules/windowglobal/log.sys.mjs

Thanks. Let me know if this feature will be implemented or any updates about using it from a web extension. Will keep waiting.

FYI: Greg has filed a bug to request access to the WebDriver BiDi protocol through an extension API at bug 1840132.

See Also: → 1840132

Not sure if it is actually a good idea to fallback to WebDriver BiDi's implementation here but better have a similar implementation for the WebExtensions API.

You need to log in before you can comment on or make changes to this bug.