Puppeteer cannot use request interception to directly block JavaScript assigning to window.location: interception controls network requests, not the JavaScript navigation mechanism. Choose the right control point: disable JavaScript before the next navigation to stop page scripts, intercept and resolve network requests to block or replace traffic, or wait for the rendered content and read it with page.content().
Choose the result you actually need
“Block window.location and return page content” can describe different jobs. A rendered DOM, a raw or replacement HTTP response, and selected text or data are different outputs. Choose the technique by outcome:
| Goal | Technique | Trade-off |
|---|---|---|
| Stop page JavaScript from initiating navigation | Disable JavaScript before the next navigation | Scripts cannot render content either |
| Cancel selected network requests | Enable interception and call request.abort() for matches |
Every intercepted request must be resolved; blocking dependencies may break the page |
| Return replacement network content | Intercept the request and call request.respond() |
The browser receives your response instead of the live server response |
| Return the browser-rendered document | Wait for the needed content, then call page.content() |
You need a readiness condition that matches the site |
| Return selected page data | Use page.evaluate() |
The result must be serializable across the page/Node.js boundary |
Request interception is useful if a navigation creates a network request you want to cancel or replace. It is not a hook for overriding window.location itself.
Return the rendered page content
Use page.content() after the browser has loaded the markup you need. It serializes the current page DOM; it does not return the original HTTP response body. A selector that identifies the expected content is usually a better readiness check than an arbitrary sleep or network-idle condition alone.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Repair Windows errors before they cause bigger problems3Fix the driver behind crashes, sound loss and screen glitches#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.
const {launch} = require('puppeteer');
async function getRenderedHtml(url) {
const browser = await launch({headless: true});
try {
const page = await browser.newPage();
await page.goto(url, {waitUntil: 'domcontentloaded'});
await page.waitForSelector('#content');
return await page.content();
} finally {
await browser.close();
}
}
getRenderedHtml('https://example.com')
.then(html => console.log(html))
.catch(error => {
console.error(error);
process.exitCode = 1;
});
Replace #content with a selector that appears when the target content is ready. The Puppeteer Page API documents page.content() and page evaluation. A Chrome for Developers example reads the DOM after network idle and adds a selector wait; it also cautions that lazy-loaded pages may need additional waiting. Network idle does not, by itself, guarantee the application has finished rendering.
Return only text or a selected value
If you need a title, a price, or a block of text rather than the complete HTML document, use page.evaluate() to read it in the page context:
const title = await page.evaluate(() => {
return document.querySelector('#content')?.textContent?.trim() ?? null;
});
The function runs in the browser page context, and its result must be serializable back to Node.js. This is usually simpler than returning a full HTML string when downstream code needs only a small value.
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.
Block selected network requests
Enable interception before navigation. Every intercepted request stalls until it is continued, aborted, answered, or fulfilled from the browser cache. A handler that does not resolve a request can hang or disrupt loading.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchconst {launch} = require('puppeteer');
async function getHtmlWithoutImages(url) {
const browser = await launch({headless: true});
try {
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', request => {
// Another registered handler may already have resolved it.
if (request.isInterceptResolutionHandled()) return;
if (request.resourceType() === 'image') {
return request.abort();
}
return request.continue();
});
await page.goto(url, {waitUntil: 'domcontentloaded'});
await page.waitForSelector('#content');
return await page.content();
} finally {
await browser.close();
}
}
getHtmlWithoutImages('https://example.com')
.then(html => console.log(html))
.catch(error => {
console.error(error);
process.exitCode = 1;
});
The handler checks isInterceptResolutionHandled() immediately before resolving a request because other listeners, including those installed by packages, may have handled it already. See Puppeteer’s Request Interception guide and interception API documentation.
Block by request type or URL
The example aborts images by resource type. You can instead test a request URL or combine conditions, but block narrowly: a stylesheet, script, worker, font, image, XHR, or fetch request can be essential to the behavior or output you want. The Chrome for Developers example permits document, script, XHR, and fetch while blocking other resource types as a particular strategy, not a universal allowlist. The right set depends on the page and the DOM you need.
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.
Do not confuse network cancellation with location blocking
If JavaScript sets window.location, the browser may start a navigation as a consequence. Interception may let you handle the resulting network request, but that is different from trapping or overriding the assignment. If your goal is to prevent scripts from running at all, use the JavaScript setting described below. If scripts are required to build the content, blocking them is likely counterproductive.
Replace a network response with your own content
Use request.respond() when you want the browser to receive supplied status, headers, and body for a matched request. For example, this returns a small HTML document in place of the top-level document response:
Recommended Free Tools
const {launch} = require('puppeteer');
async function loadReplacement(url) {
const browser = await launch({headless: true});
try {
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', request => {
if (request.isInterceptResolutionHandled()) return;
if (request.isNavigationRequest() && request.frame() === page.mainFrame()) {
return request.respond({
status: 200,
contentType: 'text/html; charset=utf-8',
body: '<!doctype html><html><body><main id="content">Replacement content</main></body></html>'
});
}
return request.continue();
});
await page.goto(url, {waitUntil: 'domcontentloaded'});
return await page.content();
} finally {
await browser.close();
}
}
loadReplacement('https://example.com')
.then(html => console.log(html))
.catch(error => {
console.error(error);
process.exitCode = 1;
});
This deliberately responds to the main-frame navigation request, so the supplied document replaces what the site would otherwise return. Adjust the match condition for your use case. Use page.content() instead when you want the DOM produced by a real browser loading and processing the page, rather than a replacement response.
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
Prevent page JavaScript from initiating navigation
Puppeteer documents page.setJavaScriptEnabled(false) as taking effect on the next navigation. It does not undo scripts that have already run on a page. Set it before navigating:
const {launch} = require('puppeteer');
async function getHtmlWithoutRunningPageScripts(url) {
const browser = await launch({headless: true});
try {
const page = await browser.newPage();
await page.setJavaScriptEnabled(false);
await page.goto(url, {waitUntil: 'domcontentloaded'});
return await page.content();
} finally {
await browser.close();
}
}
getHtmlWithoutRunningPageScripts('https://example.com')
.then(html => console.log(html))
.catch(error => {
console.error(error);
process.exitCode = 1;
});
This stops page scripts from executing on the next navigation, which can prevent script-initiated redirects. It also prevents JavaScript-rendered content from appearing. For a JavaScript application, you may get only an initial shell or incomplete markup. The JavaScript setting and other page methods are documented in the Puppeteer Page API.
Troubleshoot missing content, hangs, and unexpected navigation
The page still navigates
- Cause: Request interception is being treated as a direct override for
window.location. - Fix: Decide whether to stop scripts or handle the network request produced by navigation. Disable JavaScript before navigation to stop scripts, or intercept the resulting request if you need to cancel or replace its network response.
page.content() is missing the expected markup
- Cause: The content is rendered asynchronously, appears only after scrolling, or depends on JavaScript.
- Fix: Wait for a selector or other site-specific readiness condition; if content is lazy-loaded, perform the interaction or scrolling the page requires before serializing. Do not assume network idle proves rendering is complete.
page.goto() hangs or loading stalls after interception is enabled
- Cause: One or more intercepted requests were never resolved, or another listener has already resolved a request.
- Fix: Ensure every handler path calls
continue(),abort(), orrespond(); checkisInterceptResolutionHandled()synchronously before handling a request. Review any interception handlers registered by dependencies. Puppeteer documents the stalling rule in its interception API.
The page is broken after blocking requests
- Cause: A blocked resource was required for application logic, layout, or the desired output.
- Fix: Block fewer requests and test by resource type or URL. Keep scripts, stylesheets, XHR, fetch, or other dependencies the page needs; there is no universal resource-type allowlist.
JavaScript-disabled output is empty or incomplete
- Cause: The site builds its content in JavaScript.
- Fix: Re-enable JavaScript and wait for the relevant content, or use selective request handling if the specific concern is a resulting network navigation rather than script execution.
The returned HTML is not the raw server response
- Cause:
page.content()serializes the browser’s live DOM after document processing. - Fix: If you need different content delivered to the browser, use
request.respond(). If you need selected rendered data, extract it withpage.evaluate().
Performance and reliability considerations
- Choose readiness deliberately.
domcontentloadedprovides an initial navigation milestone, not proof that client-side rendering or lazy loading has finished. Wait for the element or condition your task actually needs. - Keep interception handlers small and complete. Each unresolved intercepted request can hold up the page. A narrow match also reduces the chance of accidentally removing dependencies.
- Do not disable JavaScript merely to avoid one redirect. That setting affects all page scripts on the next navigation, including scripts that create the content you are trying to retrieve.
- Close the browser reliably. The examples use
finallyso the browser is closed even if navigation, selector waiting, or serialization fails. - Use an output that fits the downstream task. Full DOM serialization is useful for markup;
page.evaluate()is more direct for a small serializable value;respond()is for supplying content to the browser.
Or skip the browser setup
If your goal is a screenshot or PDF rather than DOM HTML, ScreenshotNeo provides a website screenshot API and MCP server. Its screenshot request is a single GET, and its parameters include the names used by other screenshot APIs to make switching easier. See the ScreenshotNeo API documentation.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo removes cookie/consent banners, newsletter popups, and chat widgets before capture; each step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers indicate the page verdict and billing status. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and other MCP clients. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 shots.
Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.
Frequently Asked Questions
Does Puppeteer request interception block an assignment to `window.location`?
No. It handles network requests, not the JavaScript assignment itself. It can handle a request caused by a navigation.
Does `page.content()` return the original HTTP response body?
No. It returns serialized DOM from the browser’s current page.
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 →Can network idle guarantee that a page has finished rendering?
No. Wait for a site-specific selector or condition when the final content matters.
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.

