Immutable solution version
PlaywrightCrawler opens incognito contexts and localStorage throws SecurityError
Complete solution
Shows how to fix playwrightCrawler opens incognito contexts and localStorage throws SecurityError. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
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.
Steps
- 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.
When to use
You are seeing this: If localStorage throws SecurityError inside a PlaywrightCrawler page, it is not a Crawlee bug. Use this skill when you run into "PlaywrightCrawler opens incognito contexts and localStorage throws SecurityError".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
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 3 · 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>