unknown error: session deleted because of page crash from unknown error: cannot determine loading status from tab crashed with ChromeDriver Selenium

58,781

Solution 1

Though you see the error as:

Error occurred while deleting cookies from web browser!
b'Message: invalid session id\n  (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)\n'

The main exception is:

selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed

Your code trials would have given us some clues what going wrong.


Solution

There are diverse solution to this issue. However as per UnknownError: session deleted because of page crash from tab crashed this issue can be solved by either of the following solutions:

  • Add the following chrome_options:

    chrome_options.add_argument('--no-sandbox')         
    
  • Chrome seem to crash in Docker containers on certain pages due to too small /dev/shm. So you may have to fix the small /dev/shm size.

  • An example:

    sudo mount -t tmpfs -o rw,nosuid,nodev,noexec,relatime,size=512M tmpfs /dev/shm
    
  • It also works if you use -v /dev/shm:/dev/shm option to share host /dev/shm

  • Another way to make it work would be to add the chrome_options as --disable-dev-shm-usage. This will force Chrome to use the /tmp directory instead. This may slow down the execution though since disk will be used instead of memory.

    chrome_options.add_argument('--disable-dev-shm-usage')        
    

from tab crashed

from tab crashed was WIP(Work In Progress) with the Chromium Team for quite some time now which relates to Linux attempting to always use /dev/shm for non-executable memory. Here are the references :


Reference

You can find a couple of relevant discussions in:

Solution 2

In case someone is facing this problem with docker containers:

use the flag --shm-size=2g when creating the container and the error is gone. This flag make the container to use the host's shared memory.

Example

$ docker run -d --net gridNet2020 --shm-size="2g" -e SE_OPTS="-browser applicationName=zChromeNodePdf30,browserName=chrome,maxInstances=1,version=78.0_debug_pdf" -e HUB_HOST=selenium-hub-3.141.59 -P -p 5700:5555 --name zChromeNodePdf30 -v /var/lib/docker/sharedFolder:/home/seluser/Downloads selenium/node-chrome:3.141.59-xenon

Source: https://github.com/SeleniumHQ/docker-selenium

Solution 3

I was getting the following error on my Ubuntu server:

selenium.common.exceptions.WebDriverException: Message: unknown error: session deleted because of page crash from tab crashed (Session info: headless chrome=86.0.4240.111) (Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 5.4.0-1029-aws x86_64)

It turned out the the cause of the error was insufficient disk space on the server and the solution was to extend my disk space. You can check this question for more information.

Share:
58,781
mastercheef85
Author by

mastercheef85

Updated on July 05, 2022

Comments

  • mastercheef85
    mastercheef85 almost 2 years

    I'm using InstaPy which use Python and Selenium. I start the script per Cron and from time to time it crashes. So it'r really irregular, sometimes it runs well through. I'v posted on GitHub Repo as well already but didn't get an answer there, so i'm asking here now if someone has an idea why.

    It's a digital ocean ubuntu server and i'm using it on headless mode. The driver version are visible on the log. here are error messages:

    ERROR [2018-12-10 09:53:54] [user]  Error occurred while deleting cookies from web browser!
    b'Message: invalid session id\n  (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)\n'
    Traceback (most recent call last):
      File "/root/InstaPy/instapy/util.py", line 1410, in smart_run
        yield
      File "./my_config.py", line 43, in <module>
        session.follow_user_followers(['xxxx','xxxx','xxxx','xxxx'], amount=100, randomize=True, interact=True)
      File "/root/InstaPy/instapy/instapy.py", line 2907, in follow_user_followers
        self.logfolder)
      File "/root/InstaPy/instapy/unfollow_util.py", line 883, in get_given_user_followers
        channel, jumps, logger, logfolder)
      File "/root/InstaPy/instapy/unfollow_util.py", line 722, in get_users_through_dialog
        person_list = dialog_username_extractor(buttons)
      File "/root/InstaPy/instapy/unfollow_util.py", line 747, in dialog_username_extractor
        person_list.append(person.find_element_by_xpath("../../../*")
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 351, in find_element_by_xpath
        return self.find_element(by=By.XPATH, value=xpath)
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 659, in find_element
        {"using": by, "value": value})['value']
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
        return self._parent.execute(command, params)
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
        self.error_handler.check_response(response)
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, 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: headless chrome=70.0.3538.110)
      (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)
    
    During handling of the above exception, another exception occurred:
    
        Traceback (most recent call last):
      File "/root/InstaPy/instapy/instapy.py", line 3845, in end
        self.browser.delete_all_cookies()
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 878, in delete_all_cookies
        self.execute(Command.DELETE_ALL_COOKIES)
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
        self.error_handler.check_response(response)
      File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
        raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: chrome not reachable
      (Session info: headless chrome=71.0.3578.80)
      (Driver info: chromedriver=2.44.609551 (5d576e9a44fe4c5b6a07e568f1ebc753f1214634),platform=Linux 4.15.0-42-generic x86_64)
    

    Any idea what the reason could be and how to solve it?

    Thanks for the inputs. And the guys from http://treestones.ch/ helped me out.

  • Joe Healy
    Joe Healy almost 5 years
    similar issue for windows containers - stackoverflow.com/questions/55959477/…
  • JB_
    JB_ over 4 years
    I have the same error and did everything as suggested but did not solve my problem the error continues. Any different suggestions?
  • Satya Dev Yadav
    Satya Dev Yadav about 4 years
    This solution not work when selenium used with odoo 13
  • Thomas Luijken
    Thomas Luijken about 4 years
    using the chrome_options.add_argument('--disable-dev-shm-usage') argument ended my 5 hour search for fixing the tab crashes. Thank you soo much for sharing!
  • Shawn
    Shawn almost 4 years
    This is my second time revisiting this SO solution. At the end of the day looks like adding these options do mitigate the likelihood of cannot determine loading status and from tab crash, but from time to time I still face it, but it's rare enough like 1 out of 10-20 tests that I just deal it with re-attempting the test. I'm using latest chrome and selenium, so really hope the issue can be well investigated. Well perhaps it could be my ` /dev/shm` is too small for selenium sometimes, even if having --disable-dev-shm-usage.
  • undetected Selenium
    undetected Selenium almost 4 years
    @ShaungCheng /dev/shm holds the key to this problem.
  • Prakash
    Prakash about 3 years
    This great answer doesn't solve my problem. I tried to create a new question but it got closed as duplicate. Any suggestion or changes over the last year which might help me? stackoverflow.com/questions/66198126/…
  • Rafael
    Rafael about 3 years
    This solution solved my issue. I'm inside a docker container and using -v /dev/shm:/dev/shm solve the issue
  • Arnon Axelrod
    Arnon Axelrod over 2 years
    In your "didn't work" example, did you close the driver at all? And did you get the error consistently? If you didn't close the driver at all and it wasn't consistent, then maybe what you encountered is what I described in my answer, so just closing is once at the end would probably suffice.
  • Praveen
    Praveen over 2 years
    Yes, Indeed i closed at the end in the try which didn't worked as well. Also the crash was consistent. Not even passed once.
  • Smart Coder
    Smart Coder over 2 years
    options.addArguments("--disable-dev-shm-usage") works!
  • MortenB
    MortenB about 2 years
    I think `--shm-size='64m' is the default, so try to keep it as a minimum
  • fiedl
    fiedl about 2 years
    In a docker-compose.yml, this can be specified via shm_size: 2g for each service. stackoverflow.com/a/56655091/2066546