October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
Chrome

How to Disable Cookies in Selenium Headless Chrome with RSpec

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

To clear cookies already stored in a Selenium-controlled Chrome session, call driver.manage.delete_all_cookies. That clears the current browser context at that moment; it does not disable cookie storage or stop the page from setting cookies again. Headless mode is a Chrome startup option, not a cookie policy. If you need to block future cookies, decide whether you mean third-party cookies only or all cookies—the documented controls differ, and the official sources cited here do not establish a universal, version-specific Ruby/RSpec switch that blocks every cookie type.

Choose the cookie behavior your test actually needs

“Disable cookies” can mean several different things. Pick the intended behavior before changing Chrome options, or a test may appear to pass while measuring the wrong condition.

Goal What it means Suitable starting point
Remove existing cookies Clear cookies already present in the current WebDriver browser context. driver.manage.delete_all_cookies, then inspect the cookie jar.
Check what a page does without prior state Start from a clean context, load the page, then see whether it creates cookies. Clear before navigation or use a fresh browser session; inspect after page scripts run.
Restrict third-party cookies Apply a narrower policy to cookies classified as third-party. Investigate the Chrome DevTools Protocol cookie controls for the exact Chrome version; the documented control is experimental.
Prevent all cookies from being stored or sent Block both first-party and third-party cookie behavior. The cited official documentation does not provide a universal, version-specific Ruby recipe for this scope. Verify a supported mechanism for your precise Selenium and Chrome versions.

Selenium’s cookie API manages cookies in the current browser context. Chrome’s DevTools Protocol (CDP) has browser cookie clearing and inspection methods, but its documented Network.setCookieControls method is experimental and concerns third-party-cookie restriction—not a general switch for blocking every cookie type. Selenium’s cookie documentation and the CDP Network protocol reference describe those distinct capabilities.

Set up headless Chrome and clear the current cookie jar

This Ruby example uses Selenium’s Chrome options to start Chrome headlessly, then clears and checks cookies through WebDriver. It illustrates the documented API shape; it is not a version-tested recipe. Install and configure compatible Selenium, Chrome, and ChromeDriver versions for your environment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Dell Optiplex 7050 SFF Desktop PC Intel i7-7700 4-Cores 3.60GHz 32GB DDR4 1TB SSD WiFi BT HDMI Duel Monitor Support Windows 11 Pro Excellent Condition(Renewed)
  • Model: Dell OptiPlex 7050 Small Form Factor (SFF)
  • Processor: Intel Core i7-7700 3.60 GHz
  • Memory: 32GB DDR4 Ram
  • Storage: 1TB Solid State Drive (SSD) Fast Boot + Storage
  • Operating System: Windows 11 Pro (64-bit)
require 'selenium-webdriver'

options = Selenium::WebDriver::Chrome::Options.new
options.add_argument('--headless=new')

driver = Selenium::WebDriver.for(:chrome, options: options)

begin
  driver.navigate.to('https://example.test')
  driver.manage.delete_all_cookies

  cookies = driver.manage.all_cookies
  raise "Expected an empty cookie jar, found #{cookies.length}" unless cookies.empty?
ensure
  driver.quit
end

Chrome options accept command-line arguments, and Selenium’s Chrome documentation lists --headless=new among commonly used arguments. The cookie operations are separate: starting Chrome headlessly does not determine cookie policy, and delete_all_cookies deletes cookies currently present rather than preventing later writes. See the Selenium Chrome documentation and Selenium cookie documentation.

Use the same pattern in an RSpec example

Create the driver in the example or in a setup hook, and always quit it even if an expectation fails. The assertion below proves only that the jar is empty immediately after deletion; it does not prove that a page cannot create another cookie.

require 'selenium-webdriver'

RSpec.describe 'cookie behavior' do
  let(:driver) do
    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument('--headless=new')
    Selenium::WebDriver.for(:chrome, options: options)
  end

  after do
    driver.quit
  end

  it 'clears cookies in the current browser context' do
    driver.navigate.to('https://example.test')
    driver.manage.delete_all_cookies

    expect(driver.manage.all_cookies).to be_empty
  end
end

This follows the documented Ruby/WebDriver cookie-operation pattern and Chrome options interface. For a test of post-load behavior, navigate to the page after clearing, allow its relevant scripts to run, then inspect again. Selenium’s cookie documentation includes an RSpec example; the Chrome options page explains passing browser arguments.

Rank #2
Apple 2026 MacBook Neo 13-inch Laptop with A18 Pro chip: Built for AI and Apple Intelligence, Liquid Retina Display, 8GB Unified Memory, 256GB SSD Storage, 1080p FaceTime HD Camera; Blush
  • AN AMAZING MAC AT A SURPRISING PRICE — With an incredibly portable and durable aluminum design, up to 16 hours of battery life,* and the A18 Pro chip, MacBook Neo is ready to go wherever school takes you.
  • FOUR STUNNING COLORS. ONE DURABLE DESIGN — Choose from four beautiful colors — Silver, Blush, Citrus, or Indigo — each with a color-coordinated keyboard. And MacBook Neo is made with a durable recycled aluminum enclosure that helps it reach 60 percent recycled content by weight — the most ever in any Apple product.*
  • FLY THROUGH EVERYDAY ASSIGNMENTS — Whether you’re cramming for finals, using Apple Intelligence* to summarize class notes, creating presentations, or even playing the latest Apple Arcade game,* MacBook Neo delivers the performance and AI capabilities you need to get things done.
  • UP TO 16 HOURS OF BATTERY LIFE — MacBook Neo delivers all day battery life, so you can power through from early morning classes to late night study sessions without worrying about plugging in.
  • A VIBRANT 13-INCH DISPLAY* — The gorgeous Liquid Retina display on MacBook Neo supports 1 billion colors, so photos and videos pop and text is crisp for easy reading.

Test for cookies being created after navigation

Order matters. If a page is allowed to load before clearing, the clear operation removes cookies that page may just have created. That can be appropriate for a clean-state test, but it is not evidence that the page refrains from setting cookies.

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. For an empty starting state: create a fresh browser context where possible, or navigate to the relevant origin and clear its existing cookies before the action under test.
  2. Run the action: load or reload the page, interact with the feature, and wait for the application behavior under test.
  3. Inspect after the action: call driver.manage.all_cookies and assert on the cookies relevant to the test, rather than assuming the jar stays empty.
  4. Separate storage from transmission: an empty cookie jar at one point does not prove that no cookie was sent in a later request. If request behavior matters, instrument or inspect the relevant network traffic using a version-appropriate method.

For cookie inspection or clearing beyond WebDriver’s current-context API, CDP documents methods including Network.getCookies and Network.clearBrowserCookies. CDP access and method behavior depend on the browser and Selenium versions in use; do not treat the experimental third-party restriction control as an all-cookie solution. See the CDP Network protocol reference.

Third-party restriction is not the same as disabling every cookie

Third-party-cookie restrictions target cookies used in a cross-site context. First-party cookies—those associated with the site being visited—are a separate case. A test that needs to model a browser’s third-party policy should say so explicitly and verify the behavior against its Chrome version.

Rank #3
Sale
HP Essential 2026 Laptop Student Business, Ultra Light, 4GB RAM, Intel CPU
  • Performance: Powered by Intel Celeron N4500 dual-core processor with up to 2.8 GHz burst frequency and 4MB L3 cache, this HP Chromebook delivers smooth multitasking for everyday computing. With 4GB LPDDR4x-2933 RAM and Intel UHD Graphics, enjoy seamless web browsing, video streaming, and productivity apps. Chrome OS boots in seconds and updates automatically, keeping your laptop secure and running at peak performance for students, professionals, and home users.
  • Immersive 14-Inch HD Display: Experience clear, vibrant visuals on the 14-inch diagonal HD (1366 x 768) anti-glare display with 250 nits brightness and 62.5% sRGB color accuracy. The micro-edge design maximizes your viewing area with an impressive 80% screen-to-body ratio, perfect for streaming movies, video calls, and document editing. The anti-glare coating reduces eye strain during extended use, making it ideal for all-day productivity and entertainment in any lighting condition.
  • Advanced Connectivity & Ports: Stay connected with Wi-Fi 6 (2x2) for faster wireless speeds and Bluetooth 5.3 for seamless device pairing. Equipped with versatile ports including 1 USB Type-C 10Gbps (with USB Power Delivery and DisplayPort 1.4), 2 USB Type-A 5Gbps ports, 1 HDMI 1.4b, and 1 headphone/microphone combo jack. Connect external monitors, transfer files quickly, charge your device, and expand your workspace effortlessly for maximum productivity and flexibility.
  • All-Day Battery & Premium Design: The battery keeps you powered throughout your day, while the included 45W USB Type-C power adapter ensures fast charging. Featuring a sleek modern grey finish with vertical brushing pattern on the keyboard deck, this lightweight 3.35 lb Chromebook combines style and portability. The full-size modern grey keyboard and HP Imagepad provide comfortable typing and precise navigation for work, school, or entertainment on the go.
  • Enhanced Security & Multimedia: Built-in H1 secure microcontroller protects your data and privacy with enterprise-grade security. The HP True Vision 720p HD camera with integrated dual array digital microphones delivers crystal-clear video calls and online meetings. HD Audio with stereo speakers provides rich, immersive sound for music, videos, and calls. With 64GB eMMC storage, you have ample space for essential files while Chrome OS seamlessly integrates with Google Drive for cloud storage.

The CDP Network protocol marks Network.setCookieControls experimental and describes third-party cookie restriction. It does not establish a generally supported command-line argument or Ruby option that universally blocks both first-party and third-party cookies. The official Selenium Chrome options page explains argument passing but does not document a universal “disable all cookies” switch. Avoid copying an unverified Chrome flag from an unrelated version or treating a successful browser launch as proof that the intended cookie policy took effect.

Version and reliability checks

  • Match browser components: Selenium’s Chrome guidance warns that Chrome and ChromeDriver major versions should match. Check the versions used in local development and CI.
  • Check actual behavior: after applying a policy, inspect cookies after navigation and after the app action that matters. Configuration alone is not a behavioral assertion.
  • Keep headless and cookie policy separate: --headless=new requests headless Chrome; it does not mean cookies are disabled.
  • Guard teardown: use RSpec cleanup or an ensure block so failed expectations do not leave Chrome processes running.
  • Scope the assertion: test only the relevant cookie names, domains, or attributes if the application intentionally sets unrelated cookies.

Chrome and ChromeDriver compatibility guidance is available on the Selenium Chrome page. The protocol documentation is version-sensitive, so check it alongside the versions actually installed rather than assuming the current “tot” protocol reference describes every deployed browser.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common failures

The cookie jar is empty, but cookies return later

delete_all_cookies clears existing cookies only. A page can set cookies after navigation or in response to later actions. Clear at the point needed for your initial-state test, then inspect after the page runs if you are testing creation behavior.

Rank #4
Dell Optiplex 3060 Desktop Computer | Intel i5-8500 (3.2) | 32GB DDR4 RAM | 1TB SSD Solid State | Built in WiFi | Bluetooth | Windows 11 Professional | Home or Office PC (Renewed)
  • [INTEL POWERED CONTENT] - Built with a 8th Generation Hexa-Core Intel i5 and 32GB of DDR4 RAM; Modern, Windows 11 ready, with 4K support, Executive multitasking, media streaming and smooth, multi-tab web browsing; Perfect as an all-purpose multimedia computer; built for content creators; Plenty of RAM and Mass storage for photo and video editing powered by Intel HD 630
  • [LATEST WIRELESS TECH] - This Dell Desktop Computer easily connects to the internet through the Built In WiFi / Bluetooth
  • [SOLID STATE STORAGE] - This Dell Computer setup comes with an ultra-fast 1TB Solid State Drive (SSD); Setup as the primary boot device; Boot and load programs with lightning speed ; Additional expansion available
  • [BUY & OWN WITH CONFIDENCE] - From the world's largest Microsoft Authorized Refurbisher; Quality Guarantee and Free Tech Support; Award-winning Customer Service; | Support Sustainable Business
  • [MODERN HI-SPEED PORTS] - USB 3.0 (x4) | USB 2.0 (x4) | DisplayPort (x1) | HDMI Port (x1) | Audio Combo Jack (x1) | Audio Out (x1) | RJ-45 Ethernet (x1) | Internal SATA (x3)

The test still sends a cookie with a request

An empty jar checked at the wrong time does not establish what was attached to a request. Check the timing and scope of your assertion, and inspect the relevant network request with tooling supported by your browser and Selenium versions. Clearing the jar is not a persistent block policy.

A suggested cookie-disabling flag has no effect

The cited Selenium Chrome options page documents how to pass Chrome arguments, not a universal all-cookie-disable argument. Confirm that any proposed switch is documented for the Chrome version you run and test its effect; do not infer support from the browser accepting startup options.

CDP third-party controls do not block first-party cookies

That is consistent with the documented scope: the experimental Network.setCookieControls concerns third-party-cookie restriction. It should not be used as evidence of a policy covering every cookie.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Dell OptiPlex Computer Desktop PC, Intel Core i5 3rd Gen 3.2 GHz, 16GB RAM, 2TB HDD, New 22 Inch LED Monitor, RGB Keyboard and Mouse, WiFi, Windows 11 Pro (Renewed)
  • 🖥POWERFUL PROCESSOR and SUPERIOR STORAGE: Configured with top of the Intel Core i5 processor for lightning-fast, reliable and consistent performance to ensure an exceptional PC experience. 16GB RAM memory to smoothly run multiple applications and browser tabs all at once. 2TB HDD storage space to store apps, games, photos, music, and movies. Loaded with 16GB to zip through multiple tasks in a hurry without lag.
  • 🖥️New 22 Inch Full HD (1920x1080) LED monitor: with 75hz, High-Quality panel with quick refresh rate and response time. With 1080p resolution, you can enjoy gaming or a modern computing experience. 22 Inch monitor has a Smart Contrast to provide optimized image quality. Bezel-less and sleek design with glossy finish, crisp edge-to-edge visuals. Wide Viewing Angles for clarity from any viewpoint. VESA Mountable and built-in tilt options allow for a variety of monitor configurations.
  • ⌨️ +🖱️ RGB KEYBOARD AND MOUSE | RGB SPEAKER: 3 LED Colors - Blue, red, green, Backlight LED Lights for use at night time, looks amazing. The keyboard mouse and speaker are responsive, reliable, and probably plastered in RGB lights. It's important you pick the right one for your desktop.
  • 💿 WINDOWS 10 Pro LATEST: A new installation of the latest Microsoft Windows 11 Professional 64 Bit Operating System software, free of bloatware commonly installed from other manufacturers. As Microsoft's latest and best OS to date, Windows 10 Pro 64 Bit will maximize the utility of each PC for years to come. Optional software such as Anti-Virus and Office 365 can also be easily downloaded through the Microsoft Windows App Store.

Chrome fails to start or WebDriver reports a session error

Check Selenium, Chrome, and ChromeDriver installation and compatibility first; the Selenium guidance calls out matching Chrome and ChromeDriver major versions. Also verify that the selected headless argument is accepted by the Chrome build in your environment.

Or skip the browser setup

If the goal is to capture a clean website image or PDF rather than test browser cookie behavior, ScreenshotNeo is a website screenshot API and MCP server. Its capture flow accepts cookie or consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses report the page verdict and billing status in headers. AI agents can use its MCP server tools, including take_screenshot, get_page_info, and capture_pdf.

One GET request returns an image or PDF. For example, this cURL request saves a WebP screenshot of Stripe; see the ScreenshotNeo API documentation for parameters and formats.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo includes 1,000 shots per month on its free plan with no card; paid plans start at $5 for 3,000 shots. This is a screenshot service, not a substitute for a Selenium test when you need to verify cookie storage or browser policy. Sign up for 1,000 free screenshots a month, with no card required.

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

Frequently Asked Questions

Does headless Chrome disable cookies automatically?

No. Headless mode controls how Chrome runs; it does not specify cookie policy.

Can I use Selenium to block every cookie?

The cited official Selenium and CDP documentation does not establish a universal, version-specific Ruby recipe for blocking all first-party and third-party cookies. Verify a supported mechanism for the exact browser stack and test its behavior.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.