Published on

Fix for "Request Interception is not enabled!" in Puppeteer

Authors

If you're getting an error message like the following then the chances are you've missed allowing interception on your page but you're trying to intercept the URLs.

Error: Request Interception is not enabled!
    at assert (file:///Users/example/node_modules/puppeteer-core/lib/esm/puppeteer/util/assert.js:25:15)
    at HTTPRequest.continue (file:///Users/example/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPRequest.js:152:9)
    at eval (webpack-internal:///(api)/./src/defer/scraper/sbi-card.js:109:25)
    at file:///Users/example/node_modules/puppeteer-core/lib/esm/puppeteer/api/Page.js:111:32
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async HTTPRequest.finalizeInterceptions (file:///Users/example/node_modules/puppeteer-core/lib/esm/puppeteer/common/HTTPRequest.js:96:9)

Fix

// .... rest of the code ....
    await page.setRequestInterception(true);
// .... rest of the code ....

Example

const page = await browser.newPage();
await page.setRequestInterception(true);
page.on('request', (request) => {
    console.log(`Intercepting: ${request.method} ${request.url}`);
    request.continue();
});

And that's pretty much it.

Happy fixing bugs!