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.

Cannot access localStorage. Access is denied for this document.

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version: ^0.13.0
  • Platform / OS version: Windows 10

What steps will reproduce the problem?

Please include code that reproduces the issue.

await(page.evaluate(() => { localStorage.clear(); debug('localstorage cleared'); }));

What is the expected result? Localstorage should be cleared.

What happens instead? exception::Error: Evaluation failed: DOMException: Failed to read the ‘localStorage’ property from ‘Window’: Access is denied for this document.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:5
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

26reactions
LukaszGrelacommented, Oct 17, 2018

Hi @ebidel it seems to work:) like this

       // store in localstorage the token
      await page.evaluateOnNewDocument (
        token => {
          localStorage.clear();
          localStorage.setItem('token', token);
        }, 'eyJh...9_8cw');
      // open the url
      await page.goto('http://localhost:3000/Admin', { waitUntil: 'load' });
9reactions
ebidelcommented, Oct 9, 2018

Does evaluateOnNewDocument work for this use case? The code you pass it will get injected into the page before other scripts run.

https://pptr.dev/#?product=Puppeteer&version=v1.8.0&show=api-pageevaluateonnewdocumentpagefunction-args

Read more comments on GitHub >

github_iconTop Results From Across the Web

Failed to read the 'localStorage' property from 'Window'
Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. ... This exception is thrown when the...
Read more >
Iframe in Chrome error: Failed to read 'localStorage' from ...
Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
Read more >
Failed to read the 'localStorage' property from 'Window'
Failed to read the 'localStorage' property from 'Window': Access is denied for this document. I have implemented Chat in my Web site using ......
Read more >
Reading from own LocalStorage is denied within an iframe
Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document. The code to read the data from ......
Read more >
Things not available when someone blocks all cookies
Uncaught DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this 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