Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing Chrome's extension console log from the outside? #2294

Open
matanox opened this issue Aug 8, 2021 · 8 comments
Open

Processing Chrome's extension console log from the outside? #2294

matanox opened this issue Aug 8, 2021 · 8 comments

Comments

@matanox
Copy link

matanox commented Aug 8, 2021

Hi,

I find that processing the extension's logs would be of great value for CI and (headless) tests, aside being a great time saver for quickly figuring very immediately whenever your extension crashes while loading, during regular extension development.

I have tried --browser-console but it has no effect in my case where the target binary is the current Chrome Beta channel Chrome version 93 release. I would also like to eventually process the extension's console log via the command line, if such an option is available, for testing/CI and for early warnings upon source change reloads.

Chromium has a myriad of command-line startup options relating to debugging and logging levels of course, and it has a remote logging API ― they can obviously be added to the target binary via the --args option of web-ext, but I wonder if you have any kind or built-in feature (or recipe) for particularly getting the extension's console log for processing outside the browser UI; The background service worker's console being or particular interest in my view and case.

My setup:
Ubuntu 20.04, latest npm install of web-ext.

My sincere thank you for your thoughts and assistance,
Matan

@Rob--W
Copy link
Member

Rob--W commented Aug 9, 2021

web-ext does currently not offer special support for directing output from Chrome to stderr/stdout. The --verbose flag of web-ext isn't hooked up, but we could do that if it's useful.

Chrome does support a way to globally enable logging of internals (https://www.chromium.org/for-testers/enable-logging). It can be used to direct the output of the JS console to stderr or a file, but it doesn't offer the ability to do this for a specific tab in a reasonable way (technically it may be possible to do so with --renderer-cmd-prefix, but that may have other side effects).

If we are willing to dump the console of Chrome (regardless of source) to the output when --verbose is passed to web-ext, then we would have to:

  • Forward Chrome's stderr (and maybe stdout) to web-ext's stderr instead of ignoring it (like we do right now).
  • Pass the following parameters to Chromium: --enable-logging=stderr --vmodule=console=1

@Rob--W Rob--W changed the title Processing the extension console log from the outside? Processing Chrome's extension console log from the outside? Aug 9, 2021
@Rob--W
Copy link
Member

Rob--W commented Aug 19, 2021

The chrome-launcher dependency doesn't expose the ability to redirect stdout/stderr:

Chrome does unconditionally write to chrome-out.log and chrome-err.log (https://github.com/GoogleChrome/chrome-launcher/blob/b00fa22f94371f6d38d2d23e6e0b32fc7af470f0/src/chrome-launcher.ts#L197-L198), which you could read (in conjunction with the flags I mentioned above).

We cannot implement the feature requested here unless Chrome and/or chrome-launcher offers support for capturing specific logs and stderr/stdout.

@matanox
Copy link
Author

matanox commented Aug 24, 2021

Thanks for the research!

@matanox
Copy link
Author

matanox commented Aug 24, 2021

I can't say I can figure how to get chromium/chrome to provide the console log of a particular service worker either. Might chase that later and come back here.

@fregante
Copy link
Contributor

Is this a Chrome-specific issue? I don't see any stdout when running Firefox either.

I'm running tape in the content script and background page but currently I have to manually open each context to inspect the logs.

I'd love to see the console in the terminal. However I'm not too sure how I'd ask web-ext to close when the tests are done 😕

Screen Shot 8

@Rob--W
Copy link
Member

Rob--W commented Oct 1, 2021

When --verbose is set, output from Firefox is forwarded to the output.

There are various ways to close web-ext. For example by using it as a library. Or by starting a local server, and send a request to that server from the test. Upon receiving the message, send a SIGINT signal to the web-ext process.

@fregante
Copy link
Contributor

fregante commented Oct 1, 2021

When --verbose is set, output from Firefox is forwarded to the output.

What's "output from Firefox"? It's not the console I screenshotted, as far as I can see, so this is not a Chrome-specific issue.

@Rob--W
Copy link
Member

Rob--W commented Oct 1, 2021

When --verbose is set, output from Firefox is forwarded to the output.

What's "output from Firefox"? It's not the console I screenshotted, as far as I can see, so this is not a Chrome-specific issue.

I see messages from the global browser console in the output.
Things like console.log and errors from background script are not visible (but there may be a pref or environment variable (possibly MOZ_LOG) to get the log to appear too).

If you really like to output something without being drowned in logspam in stdout, then you can use dump("message here\n"); to print messages that are visible when --verbose is used with web-ext. web-ext run sets the browser.dom.window.dump.enabled preference to true, which adds the dump function to the scripting environment (including those in extensions and web pages).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants