'Getting page crash error on running tests in extra small screen size in selenium 4 - spock groovy framework

Issue

We noticed recently that our tests that use XSMALL((150..767), 1000) screen size crash in HEADLESS mode for Chrome browser (although these tests pass when run in non-headless mode) .

org.openqa.selenium.WebDriverException: unknown error: session deleted because of page crash from unknown error: cannot determine loading status from tab crashed Session info: headless chrome=99.0.4844.51)

Once you get this error, all the remaining tests in the test suite fail with the following error: org.openqa.selenium.NoSuchSessionException: invalid session id

Another observation is that this happens specifically when you try to resize the chrome browser from Large to XSMALL screen size. We are using Selenium 4 and tested with chrome versions 97, 98 and 99. Is anyone else facing similar issue and do you have suggestions on how to fix it?

What we tried

At our end, we tried couple of solutions mentioned online like increasing shared memory size, setting chrome options “--disable-dev-shm-usage” and”—no-sandbox” but nothing worked for us so far.

Sample Code

def "should render Home Page "() {
    given:
    String homePageURL = url +  lang

    when:
    webDriver.get(homePageURL)
    WebDriverUtil.setBrowserSizeWithSafeMaxWidth(webDriver, ScreenSize.XSmall)

    then:
    Assert homePage.getAd


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source