Disable JavaScript in Puppeteer

Disabling JavaScript will take up less CPU and RAM on your computer, which is to be expected. If you run something super basic, it’ll take up fewer resources.

Sometimes you might need to verify the functionalities of the websites when there is no javascript present. Also, this will help in some browsers where the javascript is disabled.

We can disable the javascript by not downloading the javascript components to the local system from the remote machine.

Most of the websites use javascript, you can view it by opening the dev tool of chrome or by pressing Ctrl + Shift + I. In the below screenshot, you can see few Javascript files downloaded while opening google.com.


Disable Javascript in Puppeteer:

To disable javascript, we need to monitor all the requests/responses flowing. Then based on the type, we can decide to terminate the request/response.

In the below example, we will load flipkart.com without using the javascript files.

const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch();
  const page = await browser.newPage();
  await page.setRequestInterception(true);
  page.on('request', request => {
    if (request.resourceType() === 'script')
  await page.goto('https://www.flipkart.com');
  await browser.close();
About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions