Session Deleted Because of Page Crash in Selenium Headless Mode

I’m encountering an issue with my Selenium script running in headless mode. The error message I receive is: “unknown error: session deleted because of page crash from unknown error: cannot determine loading status from tab crashed.” The issue occurs consistently, and I’d like to understand why it happens and how to resolve it. Any insights or suggestions would be greatly appreciated!

code:

import requests
import os
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromiumService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.os_manager import ChromeType
from webdriver_manager.core.utils import read_version_from_cmd
from webdriver_manager.core.os_manager import PATTERN

if __name__ == "__main__":
    options = webdriver.ChromeOptions()
    options.add_argument('--headless=new')
    options.add_argument('--no-sandbox')
    os.environ['WDM_SSL_VERIFY'] = '0'
    version = read_version_from_cmd(
        "/usr/bin/chromium --version", PATTERN["chromium"])
    browser = webdriver.Chrome(service=ChromiumService(ChromeDriverManager(
        chrome_type=ChromeType.CHROMIUM, driver_version=version).install()), options=options)
    browser.get("https://google.com/")
    html = browser.page_source
    soup = BeautifulSoup(html, 'html.parser')
    print(soup.title.text)
    browser.quit()

error:

(.venv) web-scraping-7217066:~/web-scraping$ python testing.py 
Traceback (most recent call last):
  File "/home/user/web-scraping/testing.py", line 21, in <module>
    browser.get("https://google.com/")
  File "/home/user/web-scraping/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 356, in get
    self.execute(Command.GET, {"url": url})
  File "/home/user/web-scraping/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 347, in execute
    self.error_handler.check_response(response)
  File "/home/user/web-scraping/.venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
  (Session info: chrome=125.0.6422.112)
Stacktrace:
#0 0x55ada5967e3a <unknown>
#1 0x55ada56512a1 <unknown>
#2 0x55ada56395c7 <unknown>
#3 0x55ada5638e1b <unknown>
#4 0x55ada5638503 <unknown>
#5 0x55ada56383f5 <unknown>
#6 0x55ada5636336 <unknown>
#7 0x55ada56369af <unknown>
#8 0x55ada5647287 <unknown>
#9 0x55ada565d55e <unknown>
#10 0x55ada5662c5b <unknown>
#11 0x55ada56370fa <unknown>
#12 0x55ada565d14f <unknown>
#13 0x55ada56df5ff <unknown>
#14 0x55ada56c0253 <unknown>
#15 0x55ada56901c7 <unknown>
#16 0x55ada5690b3e <unknown>
#17 0x55ada592e27b <unknown>
#18 0x55ada5932327 <unknown>
#19 0x55ada591adae <unknown>
#20 0x55ada5932df2 <unknown>
#21 0x55ada58ff74f <unknown>
#22 0x55ada5957128 <unknown>
#23 0x55ada59572fb <unknown>
#24 0x55ada5966f6c <unknown>
#25 0x7e09c90270e4 start_thread

dev.nix file:

# To learn more about how to use Nix to configure your environment
# see: https://developers.google.com/idx/guides/customize-idx-env
{ pkgs, ... }: {
  # Which nixpkgs channel to use.
  channel = "stable-23.11"; # or "unstable"
  # Use https://search.nixos.org/packages to find packages
  packages = [
    # pkgs.go
    pkgs.python311
    pkgs.python311Packages.pip
    pkgs.nodejs_20
    pkgs.nodePackages.nodemon
    pkgs.chromium
    pkgs.xorg.libxcb
    pkgs.glib
    pkgs.nss
    pkgs.nspr
  ];
  # Sets environment variables in the workspace
  env = {};
  idx = {
    # Search for the extensions you want on https://open-vsx.org/ and use "publisher.id"
    extensions = [
      # "vscodevim.vim"
    ];
    # Enable previews
    previews = {
      enable = true;
      previews = {
        # web = {
        #   # Example: run "npm run dev" with PORT set to IDX's defined port for previews,
        #   # and show it in IDX's web preview panel
        #   command = ["npm" "run" "dev"];
        #   manager = "web";
        #   env = {
        #     # Environment variables to set for your server
        #     PORT = "$PORT";
        #   };
        # };
      };
    };
    # Workspace lifecycle hooks
    workspace = {
      # Runs when a workspace is first created
      onCreate = {
        # Example: install JS dependencies from NPM
        # npm-install = "npm install";
      };
      # Runs when the workspace is (re)started
      onStart = {
        # Example: start a background task to watch and re-build backend code
        # watch-backend = "npm run watch-backend";
      };
    };
  };
}