question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`backgroundpage.on('console')` not working

See original GitHub issue

Steps to reproduce

  • Puppeteer version: 1.14.0
  • Platform / OS version: macOS 10.14.3
  • Node.js version: 11.6.0

What steps will reproduce the problem?

  1. git clone https://github.com/pyrho/puppeteer-bug.git
  2. yarn
  3. node example.js

The repo for this issue: https://github.com/pyrho/puppeteer-bug

What is the expected result? Messages (console.log)from the background page are caught by the backgroundPage.on('console') handler. `bg: PORT CONNECTED" should print in the node console.

What happens instead? Messages are not caught by the handler.

When manually inspecting the background page, we can see that the message is printed in the console tab: Screenshot 2019-04-17 at 16 09 00

Thank you for your time and this awesome project 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
aslushnikovcommented, Jul 14, 2019

We should disable the component extensions by default - submitted the https://github.com/GoogleChrome/puppeteer/pull/4704 for this.

1reaction
xsecommented, Apr 19, 2019

Indeed my bad. So, excuse my english, i’m pretty bad at explaining things but i’ll try since i got those bg messages. I think the issue is that there is two background pages, i actually got your example working once, but only once so that was strange, then i tried to output all console messages from all targets, it crashed so by filtering with only the targets that seems to be a background page, that works. If you add this right after the console.log('closing'); line in your example :

    let test = await browser.targets();
    let foo = [];
    for (let i=0, len=test.length; i<len; i++) {
        console.log('target '+i);
        if (test[i]._targetInfo.url.includes('background_')) {
            console.log(test[i]);
            foo[i] = await test[i].page();
            foo[i]._client.on('Runtime.consoleAPICalled', ({args, executionContextId, timestamp, type, stackTrace, context}) => {
                console.log('Runtime.consoleAPICalled');
                console.log(args);
            });
        }
    }

You can see the messages that way. working

I think you can get rid of most of the code and use .on('console', msg => console.log(bg: ${msg.text()}));

The console.log(test[i]); outputs two background pages, and since i added the listener to both i don’t know witch one is the correct one i did not dig enough into that, but you should be able to filter the correct one. Like if you take a look at the target objects, there are easy ways to differentiates both of them like i think one has your extension name inside. I don’t know if having two background pages when you specify --disable-extensions-except is normal behavior.

I don’t know if that make sense, i hope it does. EDIT: typo and maybe more clear.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Accessing console and devtools of extension's background.js
Enable developer mode ; Click on the link named background page (ManifestV2) or service worker (ManifestV3). Screenshot for ManifestV2 extensions ...
Read more >
extension.getBackgroundPage() - Mozilla - MDN Web Docs
Returns the Window of the background page if the background script is running. If the script is not running, null is returned.
Read more >
Console Stops Working - Google Groups
I'm developing a Chrome extension, and have run into a strange problem when trying to debug: When I go to my extension in...
Read more >
chrome.runtime - Chrome Developers
Use the chrome.runtime API to retrieve the background page, return details about the manifest, and listen for and respond to events in the...
Read more >
How To: Obtain diagnostic logs from Umbrella Chromebook ...
Clear console by running "Ctrl + L" before reproducing the issue. ... as is best practice) the background page is not available for...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found