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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Set the authentication cookie in the same isolated browser context that will open the page, navigate only after the cookie is present, wait for an application-level ready signal, and then call the browser’s PDF API. This sequence keeps the session available to protected HTML, API calls, images, and fonts while preventing credentials from leaking between jobs. Puppeteer and Playwright both render PDFs through a real browser; their cookie principle is the same even though their APIs differ.

The reliable cookie-to-PDF sequence

A PDF renderer that only downloads HTML cannot use a browser session. For authenticated pages, use Chromium (or another supported browser) with a dedicated context:

  1. Create an isolated browser context. Cookies and storage then belong only to this conversion job.
  2. Add the cookie before navigation. Set its name, value, host or URL, path, security flags, and expiry so the browser will send it to the target and its assets.
  3. Open the protected URL in that same context. Do not set a cookie on one page or context and render from another.
  4. Wait for authenticated readiness. Use a deterministic selector or application signal for reports that poll, open WebSockets, or load data after the initial response.
  5. Render with the PDF API. Browser PDF methods use print CSS by default; opt into screen media when that is what the design requires.
  6. Close the page, context, and browser. This disposes of the session and avoids cross-job credential reuse.

The resulting PDF is a separate artifact. It does not retain the source page’s document.cookie authority, so a reader of the file cannot use it as the original web session.

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

Puppeteer: complete authenticated PDF example

Install Puppeteer in a Node.js project, expose the session value through an environment variable, and keep the cookie out of source control and logs.

#1 Best Overall
Tengchi RCA to HDMI Converter, AV to HDMI Adapter
  • RCA Female to HDMI Video Converters Adapter : The cable is used to convert analog composite input to HDMI 1080p output, displayed on a 1080p HD TV/TV/monitor.
  • Input ports: 1xRCA Female (Yellow, White, Red), Output ports: 1xHDMI 1.3 1080p. NOT support 3D and 4K, NOT support HDMI Converts to AV
  • AV to HDMI Converter: Plug and Play, Easy to Install and Operate, Powered by External USB Cable. Note: Please hook up the USB power cable (included) to 5V 1Apower source during use (not included power supply ).
  • Support PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV formats input. For PS2,PS3,Xbox,N64,STB, VHS, VCR, DVD Players and other devices with standard composite AV input.
  • You Will Get : 1x RCA Female TO HDMI Converter, 1xHDMI cable, 1xUSB cable, 1xUser Manual. ONE YEAR WARRANTY - if you are not satisfied for any reason whatsoever, do not hesitate to contact us .
const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch();
  const context = await browser.createBrowserContext();

  await context.setCookie({
    name: 'session',
    value: process.env.SESSION_COOKIE,
    domain: 'app.example.com',
    path: '/',
    secure: true,
    httpOnly: true
  });

  const page = await context.newPage();
  await page.goto('https://app.example.com/report/42', {
    waitUntil: 'networkidle2'
  });
  await page.waitForSelector('[data-report-ready]');

  // Use this only when the page is designed for screen media.
  await page.emulateMediaType('screen');
  await page.pdf({
    path: 'report.pdf',
    printBackground: true
  });

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

The exact cookie-setting method can vary by Puppeteer version: current Page API guidance places cookie operations on the Browser or BrowserContext APIs rather than deprecated page-level methods. The stable design is still “set in the context, then navigate and print from that context.” networkidle2 is a useful initial boundary, not proof that a report is complete. The ready marker should be emitted only after the application has rendered its data.

Cookie attributes that commonly decide whether authentication works

  • Domain: A cookie for app.example.com is not automatically valid for a different host. Set the exact host (or an intentional parent domain) used by the page.
  • Path: The path must cover the report URL and any protected endpoints it calls.
  • Expiry: An expired or near-expiry session can authenticate the first request and fail during asset loading. Use a currently valid value.
  • Secure: Secure cookies require HTTPS. Keep the flag for an HTTPS production URL.
  • HttpOnly: This prevents page JavaScript from reading the cookie, but the browser still sends it on matching requests.
  • SameSite: Cross-site login flows may require a compatible SameSite setting. Inspect the actual redirect chain when a cookie appears to be ignored.

Playwright: the equivalent workflow

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const context = await browser.newContext();

  await context.addCookies([{
    name: 'session',
    value: process.env.SESSION_COOKIE,
    domain: 'app.example.com',
    path: '/',
    secure: true,
    httpOnly: true
  }]);

  const page = await context.newPage();
  await page.goto('https://app.example.com/report/42', {
    waitUntil: 'networkidle'
  });
  await page.waitForSelector('[data-report-ready]');
  await page.emulateMedia({ media: 'screen' });
  await page.pdf({
    path: 'report.pdf',
    printBackground: true
  });

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

Playwright’s page.pdf() returns a PDF buffer and uses print CSS by default. The path option writes it directly; omit that option when you need to stream or post-process the buffer.

Persistent contexts for recurring jobs

A persistent context can retain cookies and local storage in a user-data directory. Use a dedicated directory per account or job class, protect it like a credential store, and never share a production profile among unrelated jobs. For one-off conversions, a non-persistent context is safer because closing it removes the in-memory session.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
ABLEWE RCA to HDMI,AV to HDMI Converter, 1080P Mini RCA Composite CVBS Video Audio Converter Adapter Supporting PAL/NTSC for TV/PC/ PS3/ STB/Xbox VHS/VCR/Blue-Ray DVD Players
  • RCA to HDMI Converter: Converts analog RCA composite (Yellow, White, Red) input to HDMI 720P/1080P (60HZ) output,displayed on HDTV/Monitor,which can bring back your childhood memories.
  • Plug to Play: ABLEWE Mini RCA to HDMI converter no extra drivers need, just plug and play,easy to use.Please hook up the USB power cable (included) to 5V power source during use.
  • Wide Compatibility: Support source formats of PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV. Provide advanced signal processing with great precision, colors, resolutions, and details.
  • Widely Used:Widely applied to PS2,PS3,Xbox,N64, WII, STB, VHS, VCR, DVD Players and other devices with standard composite AV input.
  • Attention & Package:Please ensure to connect this rca to hdmi converter to power source to make it work.Package include:1*RCA to HDMI Converter,1*usb power cable(adapter not included),1*User Manual.

Wait for the page your users will actually see

Authentication is only the first gate. A report may fetch JSON after navigation, render charts on a timer, or load fonts and images from separate protected hosts. Wait for a semantic marker such as [data-report-ready], a known chart element, or an application promise exposed for automation. For pages with long-lived analytics requests or WebSockets, a network-idle event may never be meaningful.

  • Confirm that API responses return the authenticated status rather than a login redirect.
  • Allow the same context to request CSS, images, fonts, and data endpoints.
  • Wait for fonts when typography is important. Puppeteer’s PDF operation waits for fonts by default, but blocked or cross-origin font requests still produce fallback text.
  • Use a bounded timeout and fail the job clearly instead of writing a misleading partial PDF.

Preserve screen styling or intentionally print it

Both Puppeteer and Playwright generate PDFs with the print CSS media type by default. That can change layout, hide navigation, alter colors, or select print-specific @page rules.

  • For a screen-faithful result, call Puppeteer page.emulateMediaType('screen') or Playwright page.emulateMedia({media: 'screen'}) before printing.
  • Set printBackground: true when colored panels, chart fills, or background images are part of the design.
  • Use the page’s CSS @page size when the document defines a precise paper format; otherwise configure the PDF paper size, margins, and orientation in the API.

Changing media does not change authentication. The same cookie-bearing context must perform navigation, asset loading, and PDF capture.

Rank #3
GINGIN AV to HDMI Converter, AV to HDMI Adapter Support 720p/1080p for PS1/PS2/PS3/Xbox 360/WII/N64/SNES/STB/VHS/VCR/Blue-Ray DVD Players
  • Composite to HDMI Converter: Converts analog AV composite (Yellow, White, Red) input to HDMI 720P/1080P (60HZ) output, displayed on smart TV, Projector or HD Display, which bring back your old and cherish memories.
  • Plug to Play: This HDMI Converter no extra drivers need, just plug and play,easy to use. Please hook up the USB Power Cable (included) to 5V power source during use. Note: The Video Converters only support converts AV to HDMI, can't converts HDMI to AV.
  • Widely Used: This composite to hdmi adapter is widely applied to PS1, PS2, PS3, Xbox, N64, Wii, STB, VHS, VCR, DVD Players and other devices with standard composite AV input. Note: It can only be used when PS2 is set to RGB output.
  • Wide Compatibility: This Video Audio Converter Adapter supports source formats of PAL, NTSC3.58, NTSC4.43, SECAM, PAL/M, PAL/N standard TV. Provide advanced signal processing with great precision, colors, resolutions, and details. Important Note: This converter can't improve video quality!
  • Attention & Package: Please ensure to connect this av hdmi converter to power source to make it work. Package include: 1*AV to HDMI Adaptor, 1*USB Power Cable(adapter not included), 1*User Manual.

Diagnose the common failures

Symptom Likely cause Fix
Redirects to login Cookie host or path does not cover the URL, the value is expired, or SameSite rules reject it. Set the cookie for the exact host and path, verify expiry, and inspect the first navigation response in the same context.
PDF contains a logged-out shell The cookie was added to a different page or context, or capture happened before the app finished its redirect. Create the page from the cookie-bearing context, set the cookie before navigation, and wait for the authenticated ready marker.
Charts or images are missing Protected API or asset requests failed, or the PDF was captured too early. Check request statuses, allow the relevant hosts, and wait for a deterministic chart/image signal.
Colors or layout differ from the browser PDF generation selected print media. Emulate screen media and enable background printing, or deliberately maintain print CSS.
Text uses fallback fonts Font requests were blocked, cross-origin, or unfinished. Permit font requests in the authenticated context and wait for font readiness before printing.
Sessions leak between jobs A shared persistent profile or long-lived context contains another job’s storage. Use a new context per job, separate persistent directories by account, and close the context after writing the file.

Security and operational practices

  • Read cookie values from a secret manager or environment variable; never embed them in code, command output, screenshots, or error messages.
  • Grant the cookie only the domain and path it needs. Avoid a broad parent-domain cookie unless the application requires it.
  • Use HTTPS and short-lived service sessions where possible. Treat a persistent user-data directory as equivalent to a credential vault.
  • Do not reuse a context across customers or unrelated reports. Close it even when navigation or PDF generation throws an exception (a try/finally block is appropriate in production).
  • Record status, timing, and the report identifier—not the cookie value. Keep the PDF itself under the same access controls as the source report.

When a hosted screenshot API is a better fit

Browser automation is the right method when a private session cookie is part of the requirement. For public pages or workflows where authentication is handled outside the capture request, ScreenshotNeo can return a PNG, JPEG, WebP, or PDF from one GET request. It offers full-page capture, lazy-image loading, PDF paper size, margins, landscape mode and page ranges, plus custom headers, cookies, user agents, and authorization when your integration is allowed to provide them. Review the exact request and security options in the ScreenshotNeo documentation before sending any credential.

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.

Or skip the browser setup

For a straightforward capture, call the API directly:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
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}`);

ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, with X-Page-Verdict and X-Billed headers explaining the result. Its MCP server gives AI agents tools named take_screenshot, get_page_info, and capture_pdf. The Free plan includes 1,000 screenshots each month with no card, and paid plans start at $5 for 3,000 shots. For a private cookie session, keep the isolated-browser method above unless your security review explicitly approves passing those credentials to an external service. Create a free ScreenshotNeo account.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and cost considerations

Most conversion time is spent in browser startup, navigation, JavaScript rendering, and asset retrieval rather than the final PDF call. Reusing one browser process while creating a fresh context per job can reduce startup overhead without sharing cookies. Keep concurrency within the memory and CPU capacity of the host; many full-page, image-heavy reports can exhaust a worker before the PDF method itself fails.

Rank #4
BD&M RCA to HDMI Converter, AV to HDMI Adapter Supports PAL/NTSC for PS2, PS3, Xbox, VHS, VCR, DVD Players
  • Convert RCA to HDMI Instantly – BD&M RCA to HDMI Converter easily converts analog RCA/composite AV signals to HDMI output, allowing you to connect older devices to modern HDTVs, monitors, and projectors with clear video and audio quality.
  • Wide Device Compatibility – Supports VHS players, VCRs, DVD players, camcorders, retro gaming consoles, and more including PS1, PS2, PS3, Xbox, N64, Wii, and older AV devices with standard RCA output.
  • 1080P HDMI Output – Advanced signal processing delivers stable and sharp video output with support for 720P/1080P HDMI resolution, improving compatibility with modern TVs and displays.
  • Plug & Play Setup – No drivers or software required. Simply connect the RCA cables, HDMI cable, and included USB power cable for quick and easy installation in minutes.
  • Compact & Reliable Design – Lightweight mini converter design makes it perfect for home entertainment setups, retro gaming, travel, or converting old media collections while maintaining stable performance.

Use a deterministic readiness condition to avoid both premature captures and wasteful fixed delays. Cache only non-sensitive, immutable assets. If a report contains confidential data, disable recording and debugging artifacts that might include request headers or page content, and delete temporary files after delivery.

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

FAQ

Can I set document.cookie instead?

Not for an HttpOnly session cookie, and page-script cookies are easy to scope to the wrong host or path. Set authentication through the browser context before navigation.

Will the PDF remain logged in?

No. The PDF is a separate file and does not carry the browser session’s cookie authority.

Best Value
Convert to PDF
  • Export or Convert Text, HTML, PNG, JPG, or Camera Pictures to PDFs
  • Unlimited use
  • No ads
  • No personal data taken
  • GDPR compliant

Should I use Puppeteer or Playwright?

Choose the library that matches your existing browser coverage, cookie/context API, persistent-storage needs, waiting model, and PDF options. Both support the same context-before-navigation principle.

Why does network idle never arrive?

Polling, WebSockets, analytics, or other long-lived requests can keep the network active. Wait for an application-level selector or ready event instead.

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

Frequently Asked Questions

Can I set document.cookie instead?

Not reliably for an HttpOnly session or a differently scoped host. Set the cookie through the browser context before navigation.

Will the PDF remain logged in?

No. A PDF is a separate artifact and has no authority from the source browser session.

Should I use Puppeteer or Playwright?

Use the one that fits your project’s browser support, context API, persistence model, waiting strategy, and PDF options; both use the same cookie-before-navigation design.

Why does network idle never arrive?

Polling, WebSockets, and analytics can keep requests open. Wait for a deterministic application-ready selector or event instead.

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.