Skip to content

Crawlers are opening incognito contexts regardless of configuration #2259

Description

@cybairfly

Which package is this bug report for? If unsure which one to select, leave blank

@crawlee/browser (BrowserCrawler)

Issue description

Injection of localStorage produces error:
DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

Investigation is pointing to https://www.chromium.org/for-testers/bug-reporting-guidelines/uncaught-securityerror-failed-to-read-the-localstorage-property-from-window-access-is-denied-for-this-document

PlaywrightCrawler is opening incognito contexts for both Chrome and Firefox. Using the option optionaluseIncognitoPages is not helping.

Code sample

const crawler = new PlaywrightCrawler({
    preNavigationHooks: [
        async (crawlingContext, gotoOptions) => {
            const {page} = crawlingContext;
            await page.context().addCookies(cookies.map(cookie => ({...cookie, sameSite: 'None'})));

            {
            const data = storage;
            const code = items =>
                Object
                    .entries(items)
                    .forEach(([key, value]) => localStorage[key] = value);

            await page.evaluate(code, data).catch(error => console.warn(error.message));
            }
        },
    ],
    postNavigationHooks: [
        async (crawlingContext, gotoOptions) => {
            await crawlingContext.closeCookieModals();
        }
    ],
    headless: false,
    // proxyConfiguration: new ProxyConfiguration({ proxyUrls: ['...'] }),
    requestHandler: router,
    // Comment this option to scrape the full website.
    maxRequestsPerCrawl: 20,
    requestHandlerTimeoutSecs: 5 * 60,
    useSessionPool: true,
    persistCookiesPerSession: true,
    launchContext: {
        launcher: firefox,
        useChrome: true,
        useIncognitoPages: false
    },

Package version

latest

Node.js version

latest

Operating system

No response

Apify platform

  • Tick me if you encountered this issue on the Apify platform

I have tested this on the next release

No response

Other context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions