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.

[Feature] API for changing localStorage

See original GitHub issue

I’m trying to get the localStorage of an app via:

const storage = await context.storageState(); and it outputs: { cookies: [], origins: [] }

and then I try:

    const localStorage = await page.evaluate(() =>
      JSON.stringify(window.localStorage)
    );
    console.log(localStorage);

and I get: page.evaluate: Evaluation failed: DOMException: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

I know this page has localStorage because In between tests, I can see the localStorage in the Application tab.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:24
  • Comments:28 (6 by maintainers)

github_iconTop GitHub Comments

13reactions
b5414commented, May 12, 2022

for someone

await page.addInitScript(()=>{
	window.localStorage.setItem('key', 'value');
});
11reactions
dgozmancommented, Feb 5, 2022

@dcerniglia Look into page.addInitScript():

beforeEach(async ({ page }) => {
  // ...
  await page.addInitScript(value => {
    window.localStorage.setItem('debug', value);
  }, testConfigJson);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using the Web Storage API - MDN Web Docs
The Web Storage API provides mechanisms by which browsers can securely store key/value pairs.
Read more >
JavaScript LocalStorage: a Complete Guide
The complete guide on LocalStorage, it's API, a code walkthrough, and various trade-offs and limitations compared to other storage options.
Read more >
localStorage in JavaScript: A complete guide - LogRocket Blog
The Web Storage API consists of two mechanisms: sessionStorage and localStorage . Both sessionStorage and localStorage maintain a separate ...
Read more >
Listen for changes with localStorage on the same window
setItem; localStorage. ... createEvent now is part of an old, deprecated API. ... addEventListener('storage', function(e) { document.
Read more >
LocalStorage, sessionStorage - The Modern JavaScript Tutorial
The localStorage is shared between all windows with the same origin, so if we set the data in one window, the change becomes...
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