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.

[BUG] - Unable to obtain backgroundPage

See original GitHub issue

Context:

  • Playwright Version: 1.1.1
  • Operating System: Linux
  • Node version: 10.15
  • Browser: Chromium 83.0.4103.106 snap

Code Snippet

;(async () => {
    const pathToExtension = require('path').join(__dirname, '../dist')
    const userDataDir = require('path').join(__dirname, '../playwright')

    const browserContext = (await playwright.chromium.launchPersistentContext(userDataDir, {
      headless: false,
      args: [
        `--disable-extensions-except=${pathToExtension}`,
        `--load-extension=${pathToExtension}`,
      ],
    })) as ChromiumBrowserContext

    console.log(browserContext.backgroundPages()) // []
    const backgroundPage = await browserContext.waitForEvent('backgroundpage') // never resolves
  })()

The Chrome Extension loads fine and I can see it. Playing around with it, disabling/re-enabling, opening new tabs etc. doesn’t make a difference. Am I missing something here?

Output with debug flag:

  pw:api => chromium.launchPersistentContext started +0ms
  pw:api => chromium._innerLaunch started +411ms
  pw:api <= chromium._innerLaunch succeeded +132ms
  pw:api => cRBrowserContext._loadDefaultContext started +3ms
  pw:api <= cRBrowserContext._loadDefaultContext succeeded +0ms
  pw:api <= chromium.launchPersistentContext succeeded +1ms
[]
  pw:api => cRBrowserContext.waitForEvent started +9ms
  pw:api <= cRBrowserContext.waitForEvent failed +30s

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
vitalishapovalovcommented, Oct 5, 2021

we have the same issue, which feels critical and blocks us from proper debugging process

4reactions
aslushnikovcommented, Jun 24, 2020

@karthikiyengar awesome, thank you! I can repro now. This is a bug in CDP; we’ll fix it!

Reproduction script

a.js

const {chromium} = require('playwright');
const path = require('path');

(async () => {
  const pathToExtension = path.join(__dirname, './some-extension');
  const userDataDir = path.join(__dirname, './playwright');

  const browserContext = (await chromium.launchPersistentContext(userDataDir, {
    headless: false,
    args: [
      `--disable-extensions-except=${pathToExtension}`,
      `--load-extension=${pathToExtension}`,
    ],
  }));

  console.log(browserContext.backgroundPages());
  const backgroundPage = await browserContext.waitForEvent('backgroundpage');
  console.log('here');
})();

some-extension/manifest.json

{
  "description": "Outputs something in the console",
  "manifest_version": 2,
  "name": "Demo",
  "version": "1.0",
  "homepage_url": "https://example.com",

  "background": {
    "persistent": false,
    "scripts": ["background-script.js"]
  }
}

some-extension/background-script.js

console.log('i am a background script! Deal with me.');
Read more comments on GitHub >

github_iconTop Results From Across the Web

[crx] unable to access getBackgroundPage within chrome. ...
states that an extension panel has access to chrome.extension API. I have a panel.js file , which is loaded from panel.html, panel.html being...
Read more >
Background page runs, but popup says 'You do not have a ...
The getBackgroundPage() method doesn't retrieve the background script, it retrieves the window object associated with the background script.
Read more >
unknown error: failed to wait for extension background ...
I am getting the error "Execution Exception: unknown error: failed to wait for extension background page to load". What should I do?
Read more >
XMLHttpRequest from Worker in the background page fails
I've noticed that this happens if the request gives a 301 redirect and the target of the redirect is with a different domain...
Read more >
Safari Web Extension background request CORS issues
The ajax request in the background will always fail since it is cross origin. ... in the server's response header, the background page...
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