13

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.

Dietrich
  • 151
  • 1
  • 6

2 Answers2

13

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();
})();
Max Schmitt
  • 2,529
  • 1
  • 12
  • 26
0

In the case of @playwright/test (where you don't define browser.newContext yourself) you can set javaScriptEnabled in testOptions.

(1) In the playwright.config.js file:

const config = {
  use: {
    headless: false,
    javaScriptEnabled: false
  },
};

module.exports = config;

(2) or with test.use:

const { test, expect } = require('@playwright/test');
test.use({ javaScriptEnabled: false });

test('website without JavaScript', async ({ page }) => {
  // ...
});
theDavidBarton
  • 7,643
  • 4
  • 24
  • 51