October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Get Third-Party Cookies with Puppeteer

Puppeteer can write cookies into browser storage, but that does not ensure third-party delivery. Learn the right context methods and how to verify actual requests.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Puppeteer can write a cookie to a browser context and read cookies stored there. That does not guarantee a browser will send the cookie in a third-party context, such as an embedded frame or cross-site request: storage and cross-site delivery are separate behaviors governed by the browser and site. Use Puppeteer’s BrowserContext cookie methods, then verify the request or frame you actually care about.

Set a cookie in the context you are testing

The Puppeteer documentation labeled “Next” shows direct cookie storage operations. For an isolated test, create a BrowserContext, open the page in that context, and set and inspect the cookie on the same context:

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
const context = await browser.createBrowserContext();
const page = await context.newPage();

// Use the actual cookie name, value, and domain for your authorized test.
await context.setCookie({
  name: 'example',
  value: 'test-value',
  domain: 'third-party.example',
  path: '/',
  secure: true,
  httpOnly: true,
  sameSite: 'None',
});

await page.goto('https://first-party.example');
console.log(await context.cookies());

await context.close();
await browser.close();

This writes a cookie into browser storage; it is not a universal third-party-cookie override. In particular, SameSite=None does not by itself guarantee that a browser or website will allow the cookie in every embedded or cross-site situation. Puppeteer’s API documentation describes storage operations, not a mechanism to force third-party acceptance. Policy may vary with browser, version, settings, and site.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the API for the right browser context

Cookies belong to the browser context used by the page. Puppeteer documents that contexts isolate storage, including cookies and localStorage; cookies are not automatically shared between separate contexts.

  • Isolated context: use context.setCookie(...) and context.cookies() for pages created from that context.
  • Default context: use browser.setCookie(...) and browser.cookies() when working with the default BrowserContext. Browser-level cookie methods operate on that default context.

Keep the page, cookie write, and cookie inspection in the same context. A cookie in one context will not appear in another merely because both contexts belong to the same Browser instance.

Verify delivery, not just storage

If context.cookies() returns the cookie, the storage write succeeded. It does not establish that a cross-site request includes it. Test the specific frame or request: inspect the request’s cookie header or the server-side result, and confirm that the request is occurring under the same browser context and conditions as your intended use. A cookie visible in storage but missing from a request points to delivery policy or request context, not necessarily a failed Puppeteer write.

Cookies marked HttpOnly are not readable by page JavaScript, so use Puppeteer’s context cookie API or server-side request evidence to verify them rather than relying on document.cookie. This example targets the documented Puppeteer “Next” API; the guide and API references consulted track current documentation, so check the signatures against the exact release installed in your project.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use current cookie methods, not deprecated Page methods

Puppeteer marks page.cookies() and page.setCookie() deprecated and directs users to the Browser or BrowserContext cookie methods. Prefer the context methods for isolated tests and the browser methods for the default context. See the Puppeteer cookie guide, BrowserContext API, and Browser API.

Troubleshoot missing third-party cookies

  • The cookie is absent from context.cookies(). Confirm the write used the same BrowserContext as the page, and that the cookie’s name, domain, path, and other attributes match the test.
  • The cookie appears in storage but not in the request. Inspect the actual frame or cross-site request and browser policy. A successful storage write does not prove third-party delivery.
  • The page cannot read a cookie marked HttpOnly. That is expected; inspect browser storage through Puppeteer or verify the request at the receiving server.
  • Code using page.setCookie() or page.cookies() raises deprecation concerns. Replace those calls with the corresponding BrowserContext or Browser methods.
  • Behavior differs from another run or browser. Record the browser version, settings, site, and request context. The documented APIs do not establish a universal policy across browsers or sites.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For a website screenshot rather than a Puppeteer cookie-delivery test, ScreenshotNeo provides a one-call screenshot API. It accepts cookie and browser options, but it is not a way to force third-party cookies to be accepted. For API details, see the ScreenshotNeo documentation.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie/consent banners 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, failed loads, timeouts, and cache hits are not billed, and responses indicate the page verdict and billing status. An MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents. The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up free for 1,000 screenshots a month, with no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.