Free tools Windows power users keep installed
One-click scans. No signup required.
If page.setCookie() appears to do nothing, the usual causes are straightforward: the coroutine was not awaited, the cookie has no valid URL or domain scope, the page is still about:blank or a data: URL, or you are checking a different origin or browser context. Navigate to the target HTTP(S) origin, set an explicitly scoped cookie with await, then read it back for that same URL.
Use a minimal, correctly scoped call first
This diagnostic example follows Pyppeteer’s documented cookie fields and URL handling. Replace the URL, name and value with a cookie your application is legitimately allowed to use.
import asyncio
from pyppeteer import launch
async def main():
browser = await launch()
page = await browser.newPage()
await page.goto("https://example.com/", {"waitUntil": "networkidle2"})
await page.setCookie({
"name": "session_hint",
"value": "example",
"url": "https://example.com/",
"path": "/",
"secure": True,
"sameSite": "Lax",
})
cookies = await page.cookies("https://example.com/")
print(cookies)
await browser.close()
asyncio.get_event_loop().run_until_complete(main())
The important details are the awaited call, a normal HTTP(S) URL, and verification against the same origin. The Page.setCookie implementation validates these conditions and sends the cookie through the browser protocol.
1. Confirm that the coroutine is awaited
Page.setCookie is asynchronous. Calling it without await creates a coroutine but does not perform the browser operation. In an async def function, use:
#1 Best Overall
- Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
- Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
- Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
- Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
- 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
await page.setCookie({"name": "feature", "value": "on", "url": "https://example.com/"})
Do not hide the call behind an un-awaited helper either:
# Wrong: the coroutine is never executed
page.setCookie(cookie)
# Right
await page.setCookie(cookie)
If your program is synchronous at the entry point, run the asynchronous workflow with an event loop, as in the complete example above. A warning such as “coroutine was never awaited” is a direct indication of this problem.
2. Give the cookie a valid scope
Required fields
A cookie needs name and value. It also needs a scope. The clearest approach is an explicit url:
await page.setCookie({
"name": "prefs",
"value": "compact",
"url": "https://app.example.com/settings",
"path": "/",
})
Pyppeteer can also work with documented domain and path attributes. Use a domain that matches the host that will receive the cookie; a cookie for app.example.com is not automatically a cookie for api.example.com. A narrower path likewise excludes requests outside that path.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Repair Windows errors before they cause bigger problemsFix Now →Rank #2
- 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
- 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
- Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
- 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
- What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
Optional attributes and their effects
expires: a Unix timestamp in seconds. An expired value will not behave like a persistent cookie.httpOnly: prevents page JavaScript from reading the cookie; it can still be sent with matching requests.secure: restricts transmission to HTTPS. Do not set it when testing an HTTP-only development origin unless that is intentional.sameSite: controls cross-site sending. Use a value supported by the Chromium version shipped or selected by your Pyppeteer release.
When both URL-derived and explicit attributes are involved, make the intended host, path and scheme unambiguous. A cookie that is stored successfully can still be absent from a request because its scope does not match.
3. Do not set a cookie on about:blank or data:
When no url is supplied, the development-branch implementation attempts to infer one from the current page, but only when that page URL begins with HTTP. It explicitly rejects about:blank and data: URLs. New pages commonly start at about:blank, so set the target URL first:
await page.goto("https://example.com/")
await page.setCookie({
"name": "mode",
"value": "test",
"url": "https://example.com/",
})
Alternatively, provide the cookie URL explicitly. Using an explicit URL is still preferable because it documents the intended origin and avoids depending on the page’s transient address.
If your application renders an HTML string with a data: URL, use a legitimate HTTP(S) origin for cookie work. Data documents do not provide the normal origin relationship required for an ordinary site cookie.
Rank #3
- Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
- Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
- Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
- Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
- What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
4. Verify against the same URL and path
await page.cookies() without arguments returns cookies relevant to the current page URL. Supplying URLs filters the result to cookies affecting those URLs, according to the Pyppeteer 0.0.25 API reference. Therefore this check can be misleading:
await page.setCookie({
"name": "admin_hint",
"value": "1",
"url": "https://example.com/admin",
"path": "/admin",
})
# This may omit the cookie because the path does not match
print(await page.cookies("https://example.com/"))
# Check the URL the cookie affects
print(await page.cookies("https://example.com/admin"))
For a reliable diagnostic, print the current URL and query the exact origin and path used in the cookie:
print("current URL:", page.url)
print("stored:", await page.cookies("https://example.com/admin"))
Inspect the returned dictionary’s name, domain, path, secure, httpOnly, sameSite, session and expiry-related fields rather than checking only whether a list is non-empty.
5. Check page and browser-context identity
A BrowserContext is an independent session. Cookies set in one context are not automatically visible in another. This often happens when setup uses one page and later code creates a fresh incognito context or launches a second browser.
Rank #4
- Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
- Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
- Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
- Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
- Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
context = await browser.createIncognitoBrowserContext()
page = await context.newPage()
# Set and inspect the cookie through this same page/context
await page.goto("https://example.com/")
await page.setCookie({"name": "x", "value": "1", "url": "https://example.com/"})
print(await page.cookies("https://example.com/"))
Keep the page reference (or explicitly pass the same context) through navigation and verification. If a helper silently creates a new page, compare its context and URL with the objects used during setup. A later response can also replace or clear state; verify immediately after setCookie before adding application logic.
6. A practical debugging order
- Record the complete exception and print
page.urlimmediately before the call. - Confirm the call is inside an asynchronous function and has
await. - Navigate away from
about:blankordata:, or supply an explicit HTTP(S) cookie URL. - Check that
name,value, URL or domain, and path describe the intended origin. - Read cookies back for the exact URL and path that should receive them.
- Verify that setup and inspection use the same page and
BrowserContext. - Only then investigate navigation, redirects, application code, or server-side cookie replacement.
Common symptoms, causes and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
setCookie appears to have no effect |
Missing await |
Call it from async code as await page.setCookie(...). |
| Exception mentions an invalid page URL | Current URL is about:blank or data: |
Navigate to the target HTTP(S) origin or pass an explicit url. |
Cookie is absent from page.cookies(url) |
The supplied URL does not match the cookie’s host or path | Query the URL the cookie actually affects and review domain/path. |
| Cookie exists in one workflow but not another | Different page, browser, or browser context | Inspect and request with the same context and page lineage. |
| Cookie is stored but not sent over HTTP | secure=True or a SameSite restriction |
Use HTTPS for secure cookies and check whether the request is cross-site. |
| Protocol errors persist | Version or executable mismatch, or an unrelated browser failure | Capture a minimal traceback and all runtime versions before changing code. |
Versions and reproducibility
The project README states that “pyppeteer requires Python >= 3.8.” It also explains that first use downloads Chromium when a suitable Chrome binary is not available. Record the Pyppeteer package version, Python version, Chromium or Chrome version, operating system, launch options, current URL, cookie dictionary (with secrets removed), and traceback. The available project sources do not establish a universal version-specific cookie defect, so avoid assuming that an upgrade alone will fix a scope or context error.
Use a small reproducible script that launches one browser, creates one page, navigates to one origin, sets one harmless cookie, reads it back, and closes the browser. This separates Pyppeteer behavior from redirects, authentication middleware, service workers, and application code. Consult the Pyppeteer README for installation and browser setup notes, and its troubleshooting pointers when the minimal script fails for reasons unrelated to cookies.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Or skip the browser setup
If your actual goal is a clean image or PDF of a page rather than interactive browser state, ScreenshotNeo provides a single screenshot API call. It accepts consent banners before capture and removes more than 60 known consent platforms, newsletter popups and chat widgets; bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server exposes take_screenshot, get_page_info and capture_pdf to Claude, Cursor and other MCP clients.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo documentation for authentication, output formats and options. You can also use Python or Node.js:
Best Value
- 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
- Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
- Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
- HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
- What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
Every feature is available on every plan: 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account to try it.
When the checklist still fails
Provide a minimal reproducible script, the exact traceback, sanitized cookie payload, page URL at the instant of the call, target verification URL, context-creation code, and Python, Pyppeteer and Chromium versions. Also state whether the request is HTTP or HTTPS and whether a redirect occurs. Those details distinguish an API misuse from a browser or application-level state change without exposing credentials or session tokens.
Frequently Asked Questions
Does page.setCookie() navigate to the cookie URL?
No. It stores cookie data through the browser protocol; navigation and origin selection remain your responsibility. Navigate first or provide an explicit URL.
Why can a cookie appear in page.cookies() but not reach my server?
Storage and transmission are separate. Check host and path matching, HTTPS requirements for secure, SameSite rules, and whether the request comes from the same context.
Is this necessarily a Pyppeteer bug?
No. The documented behavior points first to awaiting the coroutine, URL validity, scope, verification filtering, and context identity. The cited sources do not establish a universal cookie-specific compatibility defect.
Quick Recap
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.

