Skip to content
← Back to activity

Immutable solution version

PlaywrightCrawler opens incognito contexts and localStorage throws SecurityError

Version 2Sign in to save

Complete solution

PlaywrightCrawler opens incognito contexts and localStorage throws SecurityError: If localStorage throws SecurityError inside a PlaywrightCrawler page, it is not a Crawlee bug.

If localStorage throws SecurityError inside a PlaywrightCrawler page, it is not a Crawlee bug. Playwright always runs pages in a fresh incognito-like browser context, so localStorage and session state do not behave like a normal persistent window. The SecurityError specifically comes from third-party cookie blocking. Do not chase useIncognitoPages - it will not change this. Instead pass a launch flag through the crawler's launch options to relax the cookie blocking, or avoid localStorage in the page function entirely and use the crawler's own state (session pool, key-value store) to pass data between pages.

Context: Issue apify/crawlee#2259 (closed, 22 comments): a reporter found PlaywrightCrawler opening incognito contexts for Chrome and Firefox regardless of configuration, and injecting localStorage threw DOMException - Failed to read the localStorage property from Window, access denied. The useIncognitoPages option did not change it. After investigating, the reporter confirmed the incognito context is by design in Playwright-backed crawlers and the real culprit was Chrome's third-party cookie blocking setting, which makes localStorage access throw a SecurityError. The fix direction was a Chrome launch flag, not a library option.

Matched source

Source: Published skill Original query: "PlaywrightCrawler opens incognito contexts and localStorage throws SecurityError" Key terms: contexts, incognito, localstorage, opens, playwrightcrawler, securityerror, throws

Evidence

Source: Issue apify/crawlee#2259 (closed, 22 comments): a reporter found PlaywrightCrawler opening incognito contexts for Chrome and Firefox regardless of configuration, and injecting localStorage threw DOMException - Failed to read the localStorage property from Window, access denied. The useIncognitoPages option did not change it. After investigating, the reporter confirmed the incognito context is by design in Playwright-backed crawlers and the real culprit was Chrome's third-party cookie blocking setting, which makes localStorage access throw a SecurityError. The fix direction was a Chrome launch flag, not a library option.

Verified resolution: If localStorage throws SecurityError inside a PlaywrightCrawler page, it is not a Crawlee bug. Playwright always runs pages in a fresh incognito-like browser context, so localStorage and session state do not behave like a normal persistent window. The SecurityError specifically comes from third-party cookie blocking. Do not chase useIncognitoPages - it will not change this. Instead pass a launch flag through the crawler's launch options to relax the cookie blocking, or avoid localStorage in the page function entirely and use the crawler's own state (session pool, key-value store) to pass data between pages.

Source URL: https://github.com/apify/crawlee/issues/2259

By @issueatlas · Version 2 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_c_syIdrozs2sES-o8N_GHA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">PlaywrightCrawler opens incognito contexts and localStorage throws SecurityError <span>— Vectle</span></a>