0

The browser opens with Se WD but the websites do not open. I have looked at Selenium opens browser but not site and When running WebDriver with Chrome browser, getting message, "Only local connections are allowed" even though browser launches properly among other related articles but none of them seem to work. I have tried it with Java 1.8, Se WD 4.7 and 4.8 with Chrome 111 and ChromeDriver for Chrome 111 version.

I tried running the code as Java application with simple code just to get started with Selenium as follows:

    System.setProperty("webdriver.chrome.driver", "Path\\to\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get("http://google.com/");`

Here is my log:

SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
Starting ChromeDriver 111.0.5563.64 (c710e93d5b63b7095afe8c2c17df34408078439d-refs/branch-heads/5563@{#995}) on port 34274
Only local connections are allowed.
Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
ChromeDriver was started successfully.
Mar 28, 2023 12:17:39 AM org.openqa.selenium.remote.http.WebSocket$Listener onError
WARNING: Invalid Status code=403 text=Forbidden
java.io.IOException: Invalid Status code=403 text=Forbidden
    at org.asynchttpclient.netty.handler.WebSocketHandler.abort(WebSocketHandler.java:92)
    at org.asynchttpclient.netty.handler.WebSocketHandler.handleRead(WebSocketHandler.java:118)
    at org.asynchttpclient.netty.handler.AsyncHttpClientHandler.channelRead(AsyncHttpClientHandler.java:78)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:336)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:323)
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:444)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:280)
    at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:442)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:166)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:788)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.lang.Thread.run(Thread.java:750)

Exception in thread "main" org.openqa.selenium.remote.http.ConnectionFailedException: Unable to establish websocket connection to http://localhost:54082/devtools/browser/01808d58-14d7-4401-8b5f-cf479860cccb
Build info: version: '4.7.0', revision: '52e3a49ea2'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_361'
Driver info: driver.version: ChromeDriver
    at org.openqa.selenium.remote.http.netty.NettyWebSocket.<init>(NettyWebSocket.java:102)
    at org.openqa.selenium.remote.http.netty.NettyWebSocket.lambda$create$3(NettyWebSocket.java:128)
    at org.openqa.selenium.remote.http.netty.NettyClient.openSocket(NettyClient.java:107)
    at org.openqa.selenium.devtools.Connection.<init>(Connection.java:77)
    at org.openqa.selenium.chromium.ChromiumDriver.lambda$new$2(ChromiumDriver.java:116)
    at java.util.Optional.map(Optional.java:215)
    at org.openqa.selenium.chromium.ChromiumDriver.<init>(ChromiumDriver.java:114)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:81)
    at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:49)
    at newpackage.TestClass.main(TestClass.java:23)

Please advice.

Martin Frank
  • 3,445
  • 1
  • 27
  • 47
Sumit M
  • 1
  • 2
  • 1
    Try URL with HTTPS. – pburgr Mar 28 '23 at 05:03
  • as you can see in your error message you get an 403 error code - that means you are not allowed (forbidden) to browse that content - google uses https (not http) protocol, so change `driver.get("http://google.com/");` to `driver.get("https://google.com/");` – Martin Frank Mar 28 '23 at 05:46
  • I have tried both, same error. The issue is not http vs https here – Sumit M Mar 28 '23 at 17:22
  • I can not even mark the answer as valid as I have "low" reputation. Perhaps, you guys can Up the question so I can atleast mark the solution as worked? – Sumit M Mar 28 '23 at 17:32

1 Answers1

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

driver = new ChromeDriver(options);

In the latest chrome version occurs this issues, By adding this argument --remote-allow-origins=* your problem will solved

Zakaria Shahed
  • 2,589
  • 6
  • 23
  • 52
  • That worked, thank you very much. I am curious to know how you got to this solution? I tried googling, stackoverflow, stackexchange, baeldung etc for possible solutions but nothing had worked – Sumit M Mar 28 '23 at 17:31
  • I can not even mark the answer as valid as I have "low" reputation. Perhaps, you guys can Up the question so I can atleast mark the solution as worked? – Sumit M Mar 28 '23 at 17:32
  • Thank you @SumitM, Happy to know it helps you. I found a solution last week when I suffer from this problem after updating the chrome driver. – Zakaria Shahed Mar 29 '23 at 06:01