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.

Support extensions with createIncognitoBrowserContext

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: ^1.6.2
  • Platform / OS version: OSX
  • Node.js version: v8.11.3

What steps will reproduce the problem?

Please include code that reproduces the issue.

  1. Use createIncognitoBrowserContext
  2. Try to enable an extension using --load-extension and --disable-extensions-except

What is the expected result?

I expect the extension to work in incognito mode. This extension works well with Allow in incognito switched on in Google Chrome, outside of Puppeteer.

What happens instead?

Got error net::ERR_BLOCKED_BY_CLIENT at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/popup.html

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:3
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
nylencommented, Apr 9, 2019

Though ugly, it’s possible to use Puppeteer to drive the extensions page and enable extensions in incognito mode:

const extensionsPage = await browser.newPage();
await extensionsPage.goto( 'chrome://extensions/' );

// https://github.com/GoogleChrome/puppeteer/issues/858
// https://github.com/GoogleChrome/puppeteer/issues/4171
const extensionCount = await extensionsPage.evaluate( `
    document
        .querySelector( 'extensions-manager' )
        .shadowRoot
        .querySelector( 'extensions-item-list' )
        .shadowRoot
        .querySelectorAll( 'extensions-item' )
        .length
` );
if ( extensionCount !== 2 ) {
    throw new Error( 'Could not find extensions on extensions page!' );
}
for ( let i = 0; i < extensionCount; i++ ) {
    const detailsButton = await extensionsPage.evaluateHandle( `
        document
            .querySelector( 'extensions-manager' )
            .shadowRoot
            .querySelector( 'extensions-item-list' )
            .shadowRoot
            .querySelectorAll( 'extensions-item' )[ ${ i } ]
            .shadowRoot
            .querySelector( 'paper-button#detailsButton' )
    ` );
    await detailsButton.click();
    await new Promise( resolve => setTimeout( resolve, 1000 ) );
    const incognitoToggle = await extensionsPage.evaluateHandle( `
        document
            .querySelector( 'extensions-manager' )
            .shadowRoot
            .querySelector( 'extensions-detail-view' )
            .shadowRoot
            .querySelector( 'extensions-toggle-row#allow-incognito' )
            .shadowRoot
            .querySelector( '#crToggle' )
    ` );
    await incognitoToggle.click();
    await new Promise( resolve => setTimeout( resolve, 1000 ) );
    const closeDetailsButton = await extensionsPage.evaluateHandle( `
        document
            .querySelector( 'extensions-manager' )
            .shadowRoot
            .querySelector( 'extensions-detail-view' )
            .shadowRoot
            .querySelector( '#closeButton' )
    ` );
    await closeDetailsButton.click();
    await new Promise( resolve => setTimeout( resolve, 1000 ) );
}

await extensionsPage.close();

However I’m having more problems after that. I need to use await browser.targets() and await target.page() to grab a handle to one of my extensions’ background pages, and this is not working. After enabling this extension in incognito mode, it has 2 background pages, and the call to await target.page() for one of them just hangs and never returns anything.

2reactions
Raiduscommented, Feb 24, 2019

I’ve found a workaround for it. Pretty naive approach but it solves my problem 😃 What I do:

  1. Define userDataDir for the browser instance like userDataDir: "./tmp"
  2. Start browser in headful mode
  3. Manually goto browser extensions => enable dev mode => enable incognito for extensions
  4. Close Browser Instance
  5. Copy created the tmp dir to tmp_ref

On each new browser instance I use this tmp_ref for my userDataDir. Browser history is in my case not an issue. Maybe it’s possible to compare the temporary files and check where those incognito settings are made.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support extensions with createIncognitoBrowserContext #3442
I have a fully functional system using puppeteer and a custom plugin for deep testing / video recording, trying to cluster it now...
Read more >
Use createIncognitoBrowserContext in Puppeteer With ...
Learn how to use createIncognitoBrowserContext function in Puppeteer framework for your next JavaScript automation project with LambdaTest Automation ...
Read more >
Puppeteer: How to set the default browser context to incognito?
const context = await browser.createIncognitoBrowserContext(); const newContextPage: Page = await context.newPage(); newContextPage.goto("https ...
Read more >
Puppeteer documentation - DevDocs
Puppeteer 7.1.0 API documentation with instant search, offline support, ... NOTE Extensions in Chrome / Chromium currently only work in non-headless mode.
Read more >
API Reference — Pyppeteer 0.0.25 documentation
coroutine createIncognitoBrowserContext () → pyppeteer.browser.BrowserContext[source]¶ ... Headless mode doesn't support navigation to a PDF document.
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