How to Check Whether JavaScript Is Enabled in Puppeteer
Use Puppeteer’s `page.isJavaScriptEnabled()` to read a page’s JavaScript setting. Learn how to change it, when changes take effect, and how to troubleshoot common issues.
To check whether JavaScript is enabled on an existing Puppeteer page, call page.isJavaScriptEnabled(). It returns a boolean: true means enabled, and false means disabled.
const enabled = page.isJavaScriptEnabled();
console.log(enabled); // true or false
This reads the page’s JavaScript setting. To change the setting, use and await page.setJavaScriptEnabled(enabled); the change takes full effect on the next navigation.
Check the setting in a complete Puppeteer script
The following ES module launches a browser, checks the default setting for a new page, disables JavaScript, navigates, checks again, and closes the browser.
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
console.log('Before change:', page.isJavaScriptEnabled());
await page.setJavaScriptEnabled(false);
await page.goto('https://example.com');
console.log('After change:', page.isJavaScriptEnabled());
} finally {
await browser.close();
}
The output of isJavaScriptEnabled() reports the setting, not whether a particular site has working scripts. A page can have JavaScript enabled while a script fails for another reason.
Install and run the example
- Install Node.js and create a project with ES module support, for example by adding
"type": "module"topackage.json. - Install Puppeteer with
npm install puppeteer. - Save the example as
check-js.jsand runnode check-js.js.
Puppeteer downloads a compatible browser as part of its standard installation. If your environment manages Chrome separately, consult the Puppeteer launch documentation for the appropriate executable configuration.
Read versus change the JavaScript setting
| Goal | API | Behavior |
|---|---|---|
| Read the setting | page.isJavaScriptEnabled() |
Returns true or false. |
| Change the setting | await page.setJavaScriptEnabled(trueOrFalse) |
Changes the setting for subsequent navigation; it does not undo scripts that already ran. |
| Run code in the page | page.evaluate(...) |
Executes an expression in the page context; it is not the documented query for the enabled setting. |
The official Puppeteer method reference documents the boolean query. The setter reference explains that a change takes effect on the next navigation and does not affect scripts that have already run.
When to disable JavaScript
Disabling scripts can help you inspect what a site serves without client-side JavaScript, compare behavior with and without scripts, or capture a static version of a page. Set the preference before navigating when you want it to apply to the page load:
const page = await browser.newPage();
await page.setJavaScriptEnabled(false);
await page.goto('https://example.com');
To enable JavaScript again, set it to true and navigate again:
await page.setJavaScriptEnabled(true);
await page.goto('https://example.com');
Changing the value after navigation does not rewind or remove effects from scripts that have already executed. Navigate again if you need a load under the new setting.
Why page.evaluate() is not the same check
page.evaluate() runs JavaScript in the page context. You could evaluate an expression to see whether it runs, but that answers a different question: whether that expression can execute in that context. It is not the dedicated Puppeteer method for reading the page’s JavaScript-enabled setting. Prefer page.isJavaScriptEnabled() when you need the setting itself. See the official Puppeteer JavaScript execution guide.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| The method is undefined | The object is not a Puppeteer Page, or the code is using a different browser automation library. |
Call the method on the page returned by Puppeteer, such as const page = await browser.newPage(). Check the installed package and its API documentation. |
The result is true, but site features do not work |
The method reports the setting; it does not confirm that a site’s scripts loaded successfully or that its application initialized. | Inspect navigation and page errors separately. Check the site’s own console or application state if you need to diagnose a specific feature. |
| Changing the setting did not alter the page already open | The new value takes full effect on the next navigation and does not affect scripts that have already run. | Set the value before navigating, or navigate again after changing it. |
await page.setJavaScriptEnabled(...) appears to have no effect |
The setting may have been changed after the relevant scripts ran, or the page was not reloaded afterward. | Set it before page.goto(), or navigate again after the setter resolves. |
| The browser fails to launch | The local installation or runtime environment may lack a compatible browser or required system dependencies. | Review the Puppeteer installation and launch guidance for your operating system and deployment environment. |
Performance, reliability, and cost considerations
Reading the setting is a synchronous boolean query; the meaningful runtime cost in a capture workflow usually comes from launching a browser and loading the page. Reuse a browser process for multiple pages where your application design permits it, and close pages and browsers when finished.
For reliable results, set the JavaScript preference before navigation when it should govern that load. A successful setting check does not guarantee successful page loading or application behavior. Puppeteer runs a browser under your control, so account for browser installation, compute, memory, and the time spent loading each target. These costs depend on your environment and workload; no fixed benchmark or price applies here.
Or skip the browser setup
If your goal is to get a website screenshot rather than inspect Puppeteer’s JavaScript setting, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns an image or PDF. See the ScreenshotNeo API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"},
timeout=90,
)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
ScreenshotNeo accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed. Its MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots.
Sign up free and get 1,000 screenshots a month with no card.
FAQ
Does isJavaScriptEnabled() return a promise?
No. It returns a boolean, so call it directly without await.
Does the method tell me whether the current page used JavaScript?
No. It reports whether JavaScript is enabled for the page. It does not report which scripts ran or whether they succeeded.
Can I check the setting before navigating?
Yes. Create the page and call page.isJavaScriptEnabled() before navigation. Set the desired value with page.setJavaScriptEnabled() before loading the site if it should apply to that load.


