What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Disable JavaScript in a Selenium-controlled headless Chrome session by combining Chrome’s --headless argument with the profile preference profile.default_content_setting_values.javascript set to 2. The preference is a practical, version-sensitive configuration rather than a precisely documented ChromeDriver contract, so verify the result with a page whose visible output changes only when JavaScript runs.

What headless mode does—and does not do

Headless Chrome runs without a visible browser window. It does not disable JavaScript. Chrome’s current headless mode uses the same browser implementation as normal Chrome, and pages can still execute scripts while Chrome builds the DOM.

JavaScript blocking is a separate browser-content setting. Selenium passes that setting to ChromeDriver through Options.add_experimental_option("prefs", ...). The example below creates an isolated temporary profile, which is ChromeDriver’s normal behavior.

Complete Selenium Python example

Install Selenium and ensure a compatible Chrome browser and ChromeDriver are available. Recent Selenium versions can often manage the driver automatically, but the browser and driver still need to be compatible.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HP 14'' Chromebook Laptop, Intel Celeron N4120, 4 GB RAM, 64 eMMC, HD Display, Chrome OS, Intel UHD Graphics 600, Long Battery Life, Ash Gray Keyboard (14a-na0226nr, 2022, Mineral Silver) (Renewed)
  • FOR HOME, WORK, & SCHOOL – With an Intel processor, 14-inch display, custom-tuned stereo speakers, and long battery life, this Chromebook laptop lets you knock out any assignment or binge-watch your favorite shows.
  • HD DISPLAY, PORTABLE DESIGN – See every bit of detail on this micro-edge, anti-glare, 14-inch HD (1366 x 768) display (1); easily take this thin and lightweight laptop PC from room to room, on trips, or in a backpack.
  • ALL-DAY PERFORMANCE – Reliably tackle all your assignments at once with the quad-core, Intel Celeron N4120—the perfect processor for performance, power consumption, and value (2).
  • 4K READY – Smoothly stream 4K content and play your favorite next-gen games with Intel UHD Graphics 600 (3) (4).
  • MEMORY AND STORAGE – Enjoy a boost to your system’s performance with 4 GB of RAM while saving more of your favorite memories with 64 GB of reliable flash-based eMMC storage (5).
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument("--headless")
options.add_experimental_option(
    "prefs",
    {
        "profile.default_content_setting_values.javascript": 2,
    },
)

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")
    print(driver.title)
    print(driver.page_source[:500])
finally:
    driver.quit()

The value 2 requests that JavaScript be blocked for the profile. Keep the try/finally block: it closes Chrome even when navigation or inspection raises an exception.

Use an explicit headless window size when layout matters

Headless sessions may use a small default viewport. Set one when screenshots, responsive breakpoints or element coordinates matter:

options.add_argument("--window-size=1440,1000")

Place this line before creating the driver. It changes the viewport, not the JavaScript policy.

Use a persistent profile only when you need persistence

For a setting that must survive sessions, supply a dedicated profile directory:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
options.add_argument("--user-data-dir=/absolute/path/to/selenium-profile")

Do not launch concurrent Chrome sessions against the same profile directory. A persistent profile can also contain cookies, extensions and other preferences that make a test less isolated. For reproducible checks, prefer ChromeDriver’s fresh temporary profile.

How to verify that JavaScript is disabled

A page that merely loads is not proof that scripts are blocked. Use a controlled page in which a script changes visible text or adds an element, then inspect the resulting DOM.

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By

options = Options()
options.add_argument("--headless")
options.add_argument("--window-size=1200,800")
options.add_experimental_option(
    "prefs",
    {"profile.default_content_setting_values.javascript": 2},
)

driver = webdriver.Chrome(options=options)
try:
    driver.get("file:///absolute/path/to/javascript-test.html")
    marker = driver.find_element(By.ID, "js-marker")
    print("Marker text:", marker.text)
finally:
    driver.quit()

Your test file can contain a static element and a script that changes it:

<!doctype html>
<div id="js-marker">Static text</div>
<script>
  document.getElementById("js-marker").textContent = "Changed by JavaScript";
</script>

With JavaScript blocked, the visible text should remain “Static text.” Run the same page once without the preference to confirm that the test itself works. This is a behavioral check for the session you launched; it is not proof that every script execution context in every Chrome release is blocked.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Reload when testing a page dependency

Chrome’s developer guidance recommends reloading after changing JavaScript settings. A page may have already rendered cached or server-generated content, while later interactions depend on scripts. Navigate or reload under the blocked setting before drawing conclusions.

Why the preference is version-sensitive

ChromeDriver documents accepting Chrome preferences for its temporary session profile, and Selenium exposes the Python options API used above. The exact preference key and numeric value shown here are widely used in practice, but the official capability documentation does not establish them as a permanent cross-version contract. Check the behavior with the Chrome and driver versions installed in your environment after upgrades.

Use current unified headless mode with --headless. Older examples may show --headless=new; that was relevant during the transition to unified headless. The old separate implementation is available as the standalone chrome-headless-shell beginning with Chrome 132.0.6793.0, not as a reason to replace the normal current argument in Selenium scripts.

Temporary profile versus persistent profile

Choice Persistence Isolation Parallel suitability Use it when
ChromeDriver temporary profile Ends with the session High; existing browser preferences are not reused Best option for separate sessions You need repeatable tests or one-off inspection
Dedicated user-data-dir Survives sessions Lower; cookies and other profile state persist Use a different directory per concurrent session You intentionally need retained cookies or settings

Never point automation at a profile currently used by an interactive Chrome process. Locking and profile corruption can cause startup failures or contaminate test results.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What breaks when JavaScript is blocked

  • Client-rendered text, menus and application shells may remain empty.
  • Login, consent dialogs and controls that require event handlers may not work.
  • Content fetched after navigation through JavaScript will not appear.
  • Some pages may display a browser-side error, a loading state or an incomplete layout.

These outcomes are expected: disabling JavaScript changes how sites are allowed to run scripts. If your goal is to inspect server-rendered HTML, this is useful. If you need the final application state, blocking scripts is the wrong test condition; capture a normal JavaScript-enabled session as a comparison.

Troubleshooting

Chrome opens, but scripts still appear to run

  • Confirm the preference is nested under "prefs" and the key is spelled exactly.
  • Make sure the option is attached before webdriver.Chrome(options=options).
  • Use a fresh temporary profile; a persistent profile may contain conflicting settings.
  • Verify with a controlled page rather than a site whose content is already in the initial HTML.
  • Check the installed Chrome and ChromeDriver versions after an upgrade; the preference is version-sensitive.

ChromeDriver cannot start

Check that Chrome is installed, ChromeDriver can be found, and their major versions are compatible. If you use a custom binary, set it explicitly:

options.binary_location = "/path/to/chrome"

Also check that the profile directory is writable and is not already locked by another Chrome process.

Rank #2
Samsung Chromebook Plus V2 2-in-1 Laptop- 4GB RAM, 64GB eMMC, 13MP Camera, Chrome OS, 12.2", 16:10 Aspect Ratio- XE520QAB-K03US Light Titan
  • TWEIGHT 2-in-1 DESIGN At just under 3 pounds, the Chromebook Plus is incredibly lightweight. You can easily fold it into tablet mode for comfortable viewing and browsing
  • BUILT-IN PEN Experience the power of the incredibly precise built-in pen that never needs charging. It's always ready to write, sketch, edit, magnify and even take screenshots
  • DUAL CAMERA Fold your laptop into tablet mode to capture clear shots and even zoom in for a closer look with the revolutionary 13MP world-facing camera with autofocus
  • CHROME OS AND GOOGLE PLAY STORE Create, explore and browse on a bigger screen with the tools you use every day —all on the secure Chrome OS
  • POWER AND PERFORMANCE Tackle anything with a long-lasting battery and Intel Celeron processor. Store more with 64GB of built-in memory and add up to 400GB with a microSD card.Bluetooth v4.0

The page is blank or incomplete

That usually means the page relies on JavaScript for content or interaction. Compare the blocked session with a JavaScript-enabled run, inspect driver.page_source, and decide whether server-rendered markup is sufficient for your task.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Navigation times out

Blocking scripts does not guarantee that every resource or server response is fast. Set a deliberate page-load timeout and catch the exception so the driver is still closed:

from selenium.common.exceptions import TimeoutException

driver.set_page_load_timeout(30)
try:
    driver.get("https://example.com")
except TimeoutException:
    print("Navigation exceeded 30 seconds")

Do not omit the final driver.quit(). A timeout can leave Chrome processes behind if cleanup is not handled.

File URLs behave differently from HTTPS pages

A local file:// test is useful for a deterministic marker, but origin and security behavior differ from a hosted site. Validate your automation against the actual HTTPS pages and policies you care about.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability considerations

Headless mode removes the visible window; it is not a promise of a particular speed improvement. JavaScript blocking can reduce client-side work, but pages may still wait on network requests, redirects, fonts or server-side delays. Do not publish a performance number unless you have measured the same URL, browser version, machine and network conditions.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For reliable runs:

  • Pin or record Chrome, ChromeDriver and Selenium versions.
  • Create a new temporary profile for isolated jobs.
  • Set explicit timeouts and always quit the driver.
  • Use a stable test page to detect regressions after browser updates.
  • Record whether the page was server-rendered, partially rendered or script-dependent.

Or skip the browser setup

If you need a clean website screenshot rather than a Selenium experiment, ScreenshotNeo provides a single HTTP request that returns PNG, JPEG, WebP or PDF. Before capture it accepts cookie and consent banners and removes more than 60 known consent platforms, newsletter popups and chat widgets; each step can be disabled. Bot checks, CAPTCHAs, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers.

See the ScreenshotNeo API documentation for all options, including full-page and element capture, device presets, dark mode, custom CSS and JavaScript, waits, request blocking, cookies, headers, geolocation, PDFs, caching, signed links, asynchronous jobs, bulk capture and usage reporting.

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}`);

ScreenshotNeo also has an MCP server with take_screenshot, get_page_info and capture_pdf tools for Claude, Cursor and other MCP clients. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.

FAQ

Does --headless disable JavaScript?

No. It only runs Chrome without a visible window. Add the profile preference separately.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can I disable JavaScript after the driver starts?

The dependable approach is to set the preference before creating the driver, then navigate in that session. For a changed policy, create a new isolated session and verify it.

Will disabling JavaScript block JavaScript in every frame?

Use the controlled-page check for your Chrome and driver versions. The preference is practical and version-sensitive, not a guarantee documented as an immutable cross-version contract.

Should I use a real user profile?

Usually no. A fresh temporary profile gives better isolation. Use a dedicated persistent directory only when retaining profile state is an explicit requirement.

Frequently Asked Questions

Does headless Chrome itself disable JavaScript?

No. Add the JavaScript content-setting preference to Chrome options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How can I tell whether blocking worked?

Load a controlled page whose visible text changes only through a script, then inspect the DOM under the blocked session.

Why is my page incomplete?

The site likely generates content or interactions with JavaScript; compare it with a JavaScript-enabled run.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.