Disable JavaScript in Playwright tests

Test a no-JavaScript baseline with test.use(), a global setting, or a dedicated Playwright project.

Best practices
Illustration of software development and testing

Set javaScriptEnabled: false in Playwright Test to disable page JavaScript. Use test.use() inside a test.describe() block for one group, at file scope for the file, or in the configuration's use section for a broader default.

This checks how a page behaves without scripts: whether server-rendered content, links, and native form submissions still work. It is useful for progressive enhancement and script-failure planning. A no-JavaScript test is not a screen-reader simulation or a complete accessibility audit; screen readers commonly operate with JavaScript enabled.

Disable JavaScript for a group

import { test, expect } from '@playwright/test';

test.describe('without JavaScript', () => {
  test.use({ javaScriptEnabled: false });

  test('core content remains available', async ({ page }) => {
    await page.goto('https://example.com');
    await expect(page.locator('h1')).toBeVisible();
  });
});

Set a global default

// playwright.config.ts
import { defineConfig } from '@playwright/test';

export default defineConfig({
  use: { javaScriptEnabled: false },
});

A separate project is often more useful because it runs the same suite in both modes. Put this projects property inside defineConfig():

projects: [
  { name: 'js-on', use: { javaScriptEnabled: true } },
  { name: 'js-off', use: { javaScriptEnabled: false } },
]

What to verify

  • Headings, body content, and navigation are available from the server-rendered page.
  • Forms can use native submission where that is part of the intended design.
  • Important links use real <a href> destinations rather than script-only navigation.
  • The page provides appropriate fallback content or messaging.

Frequently asked questions

Can Playwright still click elements?

Yes. Browser automation remains available with page JavaScript disabled. However, a click will not make a disabled page event handler run. Native link navigation and form behavior remain useful things to test.

Can I block script downloads instead of disabling JavaScript entirely?

Yes. Register a route before navigation, for example:

await page.route('**/*', route =>
  route.request().resourceType() === 'script'
    ? route.abort()
    : route.continue()
);

This targets script requests, including URLs that do not end in .js. It does not disable inline scripts or scripts already loaded, and an aborted request is not the same as a slow response. Account for service workers when testing request interception.

What happens to a client-rendered SPA?

An application that needs JavaScript to render its content may show little more than an empty shell. Depending on the product's requirements, consider server-side rendering, static generation, or at least a useful noscript message.

References

Get a tailored plan

Contact us

Join the community

Scan with WeChat
to join the community

Try Guance

Start online and pay only for what you use.

Get started

Choose a Guance plan

Code hosting