Use page.evaluate() to set sessionStorage in a page that has already loaded. If the site reads the value while starting up, register the code with page.evaluateOnNewDocument() before navigating so it runs before the page’s scripts.
Set sessionStorage after a page has loaded
sessionStorage belongs to the page’s JavaScript context, so run the Storage API call with Puppeteer’s page.evaluate():
As an Amazon Associate I earn from qualifying purchases.
await page.evaluate((key, value) => {
sessionStorage.setItem(key, value);
}, 'token', 'example-value');
page.evaluate() executes the function in the page and returns its result; Puppeteer also waits for a promise returned by the function. Pass the key and value as arguments rather than building a JavaScript string. See the Puppeteer Page.evaluate() documentation.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minuteSet the value before the site’s scripts run
If application startup code needs to read the value, register an initializer before calling page.goto():
#1 Best Overall
await page.evaluateOnNewDocument((key, value) => {
sessionStorage.setItem(key, value);
}, 'token', 'example-value');
await page.goto('https://example.com');
Puppeteer documents that the function runs after a document is created but before its scripts run. It also runs when a child frame is attached or navigated. Registering it after a page has loaded does not run it retroactively in that document; register it first, then navigate or reload when startup timing matters. See Puppeteer Page.evaluateOnNewDocument().
Verify the stored value
Read the value back in the page context to confirm that it was written:
Rank #2
const stored = await page.evaluate((key) => {
return sessionStorage.getItem(key);
}, 'token');
console.log(stored); // 'example-value'
getItem() returns null when the key is absent. If the read fails or returns null, check that the write ran in the intended page and at the right time, then check the origin and storage restrictions below. The page-context behavior is described in the Puppeteer API; storage reads and writes are part of the MDN sessionStorage reference.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Repair Windows errors before they cause bigger problemsFix Now →Understand which page can see the value
Origin: scheme, host, and port
Storage is associated with an origin, which is defined by scheme, host, and port. A value written on one origin is not available to a different origin—even if the pages have similar names or paths. For example, changing from HTTP to HTTPS changes the origin. See the MDN same-origin policy guide.
Tab and page session
sessionStorage is also partitioned by top-level browsing context. A page session survives reloads, but ends when its tab or window session ends; a different tab should not be assumed to share the same storage area. See MDN’s sessionStorage documentation.
BrowserContext isolation
Puppeteer BrowserContexts provide isolation between browser sessions. The Puppeteer browser-management guide specifically notes that cookies and local storage are not shared between contexts. Use separate contexts when automation runs should not share browser state; session storage still follows its own origin and tab boundaries. See Puppeteer’s browser management guide.
Rank #4
Handle storage errors and timing issues
SecurityErroron access: Check the current page URL and whether it has a valid scheme, host, and port. Storage access may also be blocked by browser policy or unavailable for an opaque origin. The MDN sessionStorage reference describes these restrictions.- The app behaves as if the key is missing: If startup code reads the key before your write, move the initializer to
evaluateOnNewDocument()and register it before navigation. A later registration does not change what scripts already read. - The value disappears on another page: Confirm that the destination has the same scheme, host, and port, and that it is in the same tab session. Session storage is not general cross-origin or cross-tab state.
- The test sees state from another run: Check that runs use the intended BrowserContext and page. Separate contexts are useful for isolating automation state.
Or skip the browser setup
If the goal is a clean screenshot rather than testing application behavior, ScreenshotNeo can return a screenshot from one GET request. It accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. It also offers an MCP server for AI agents, with the tools take_screenshot, get_page_info, and capture_pdf.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for the request and available options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month, with no card required.
Quick Recap
Best Value
- Used Book in Good Condition
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




