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.
Asked
Active
Viewed 3,941 times
2 Answers
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
-
Hi, In the case of python, you can use: page = browser.new_page(user_agent="
", java_script_enabled=False) – DANIEL ROSAS PEREZ Jan 13 '22 at 23:13
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