35

I have this error stack when I try to execute a set of Selenium Webdriver tests into Azure DevOps driver to remote server:

2023-03-08T21:06:46.9827484Z Running Test 66728 Mobile Web - Pick Task
2023-03-08T21:06:46.9827843Z Test Description https://dev.azure.com/Corporation/%20FootPrint/_workitems/edit/66728
2023-03-08T21:06:47.2244460Z Starting ChromeDriver 111.0.5563.41 (976ef12907ef9b413c2d929c043307b415d27b9e-refs/branch-heads/5563@{#737}) on port 35235
2023-03-08T21:06:47.2248489Z Only local connections are allowed.
2023-03-08T21:06:47.2273309Z Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
2023-03-08T21:06:47.2530381Z ChromeDriver was started successfully.
2023-03-08T21:06:50.3292859Z Mar 08, 2023 4:06:50 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
2023-03-08T21:06:50.3319163Z WARNING: Invalid Status code=403 text=Forbidden
2023-03-08T21:06:50.3320374Z java.io.IOException: Invalid Status code=403 text=Forbidden
2023-03-08T21:06:50.3321045Z    at org.asynchttpclient.netty.handler.WebSocketHandler.abort(WebSocketHandler.java:92)
2023-03-08T21:06:50.3321498Z    at org.asynchttpclient.netty.handler.WebSocketHandler.handleRead(WebSocketHandler.java:118)
2023-03-08T21:06:50.3322255Z    at org.asynchttpclient.netty.handler.AsyncHttpClientHandler.channelRead(AsyncHttpClientHandler.java:78)
2023-03-08T21:06:50.3326071Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
2023-03-08T21:06:50.3334206Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
2023-03-08T21:06:50.3334813Z    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
2023-03-08T21:06:50.3335472Z    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
2023-03-08T21:06:50.3336148Z    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:346)
2023-03-08T21:06:50.3336823Z    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:333)
2023-03-08T21:06:50.3337255Z    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:454)
2023-03-08T21:06:50.3337683Z    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
2023-03-08T21:06:50.3339980Z    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
2023-03-08T21:06:50.3340463Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
2023-03-08T21:06:50.3343324Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
2023-03-08T21:06:50.3344253Z    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
2023-03-08T21:06:50.3344757Z    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
2023-03-08T21:06:50.3345262Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
2023-03-08T21:06:50.3345959Z    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
2023-03-08T21:06:50.3346524Z    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
2023-03-08T21:06:50.3346956Z    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
2023-03-08T21:06:50.3347371Z    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
2023-03-08T21:06:50.3347781Z    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
2023-03-08T21:06:50.3348183Z    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
2023-03-08T21:06:50.3348555Z    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
2023-03-08T21:06:50.3349009Z    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
2023-03-08T21:06:50.3349522Z    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
2023-03-08T21:06:50.3350108Z    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
2023-03-08T21:06:50.3350574Z    at java.lang.Thread.run(Thread.java:748)

When I run the same code from my pc it's running fine. Do you know is it possible that WebDriver code is missing and for that reason I get this error?

10 Answers 10

67

Going through a bunch of different posts about this that showed up today. The fix in most cases is to add a chromedriver option to your driver instance. This is what got things working for me again.

Example:

options.addArguments("--remote-allow-origins=*")
Sign up to request clarification or add additional context in comments.

3 Comments

While it works, if feels like potential security threat, is there specific origin that can be set instead of wildcard?
@MichaelBabich you're right. The way I'm using the ChromeDriver is to test an internal tool so it doesn't matter much. You're comment is very relevant. But, I don't have the answer... Sorry.
Just added that (Chrome V111). Chome started normally via Selenium but then got an error 500. Could not start a new session. Response code 500. unknown error: DevToolsActivePort file doesn't exist. (The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed. -> but it's still running
14

The related Selenium issue is https://github.com/SeleniumHQ/selenium/issues/11750.

It will also work for Selenium 4.5+ if you upgrade to use the Java 11+ HTTP client, as described in https://www.selenium.dev/blog/2022/using-java11-httpclient/

Basically, add a dependency to

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-http-jdk-client</artifactId>
  <version>4.8.1</version>
</dependency>

and set the system property

System.setProperty("webdriver.http.factory", "jdk-http-client");

1 Comment

This works - thank you very much - but I am still confused why we need it?
12

Using v111.0 this error message...

2023-03-08T21:06:50.3292859Z Mar 08, 2023 4:06:50 PM org.openqa.selenium.remote.http.WebSocket$Listener onError
2023-03-08T21:06:50.3319163Z WARNING: Invalid Status code=403 text=Forbidden

...is the result of devtools_http_handler rejecting an incoming WebSocket connection from the http://localhost:xxxxx origin.


Quick Solution

As the ChromeDriver verbose log suggests:

[32332:259:0214/190812.204658:ERROR:devtools_http_handler.cc(766)] Rejected an incoming WebSocket connection from the http://localhost:58642 origin. Use the command line flag --remote-allow-origins=http://localhost:58642 to allow connections from this origin or --remote-allow-origins=* to allow all origins.

A quick fix to this issue would be to add the argument --remote-allow-origins=* as follows:

  • Java:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--remote-allow-origins=*");
    WebDriver driver = new ChromeDriver(options);
    

References

You can find a couple of detailed discussions in:

Comments

5

You should add the below code for issue :java.io.IOException: Invalid Status code=403 text=Forbidden and websocket handler

            ChromeOptions option = new ChromeOptions();
            option.addArguments("--remote-allow-origins=*");

            WebDriverManager.chromedriver().setup();
            driver = new ChromeDriver(option);

1 Comment

not solving the issue -
1

This problem occurs after update Chrome to version 111

Solution:

ChromeOptions chromeOptions = new ChromeOptions();

chromeOptions.addArguments("--remote-allow-origins=*","ignore-certificate-errors");

driver = new ChromeDriver(chromeOptions);

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
1

This error is fixed in Selenium version 4.9.0 with no workarounds needed for projects using JDK 8

Comments

1

this is my sample test class:

public class AppTest

WebDriver driver ;
public static final String path = "/yourabsolutepath/chromedriver";
// im using linux, so no .exe, chromedrive is my driver not a folder.


public static void main(String[] args) {

}

@BeforeTest
public void doThisBefore(){
    ChromeOptions option = new ChromeOptions();
    option.addArguments("--remote-allow-origins=*");

    System.setProperty("webdriver.chrome.driver", path);
    driver = new ChromeDriver(option);
    driver.get("https://selenium.dev/");
}

and this is a basic test :

    @Test
public void getTitle(){
    String title = driver.getTitle();
    System.out.println(driver.getTitle());
    Assert.assertEquals(title,"Selenium");
}

Comments

0

I tried all of the above and found that none of them worked. However, I am on chrome version 111.0.5563.64. I tried running the latest version of the chrome driver with chrome version 110 and it worked fine.

Comments

0

Or just update the Selenide version to '6.12.2' if used Selenide in your project. This issue has already been fixed

Comments

0

In my case the issue was solved after adding <artifactId>selenium-java</artifactId>:

<dependency>
  <groupId>org.seleniumhq.selenium</groupId>
  <artifactId>selenium-java</artifactId>
  <version>4.8.2</version>
</dependency>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.