playwright

Disable Javascript in Playwright


Is it possible to define a browser with Javascript disabled to simulate how a crawler would view a page? There should be an option that can be passed.


Solution

  • You can pass javaScriptEnabled in the BrowserContext options:

    const playwright = require("playwright");
    
    (async () => {
      const browser = await playwright.chromium.launch();
      const context = await browser.newContext({
        javaScriptEnabled: false
      });
      const page = await context.newPage();
      // ...
      await browser.close();
    })();