Chrome升级后QAF启动Chrome Driver报403 Forbidden错误的解决方法
解决QAF框架启动Chrome Driver时的403 Forbidden错误
问题场景
Windows 10本地环境中,Chrome浏览器完成最新升级后,使用QAF(Quantum Web App)自动化框架启动Chrome Driver时,抛出「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:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:436) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:327) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:314) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:435) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:279) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:251) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.handler.logging.LoggingHandler.channelRead(LoggingHandler.java:280) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:357) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:365) 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:722) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:995) 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:748)
解决方案
该错误由Chrome升级后新增的跨域安全限制导致,需为Chrome添加--remote-allow-origins=*启动参数,在QAF中有两种配置方式:
方式1:通过application.properties配置
找到项目中的application.properties文件,添加或修改以下配置项:
# 配置Chrome额外启动参数 chrome.additional.capabilities={"chromeOptions":{"args":["--remote-allow-origins=*"]}}
若已有chrome.additional.capabilities配置,只需在args数组中追加参数即可,例如原配置为:
chrome.additional.capabilities={"chromeOptions":{"args":["start-maximized"]}}
修改后变为:
chrome.additional.capabilities={"chromeOptions":{"args":["start-maximized", "--remote-allow-origins=*"]}}
方式2:通过代码动态配置
如需在代码中动态设置参数,可在初始化Driver的逻辑中添加:
DesiredCapabilities capabilities = new DesiredCapabilities(); ChromeOptions options = new ChromeOptions(); options.addArguments("--remote-allow-origins=*"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); // 传递给QAF的Driver工厂 DriverManager.getDriver(capabilities);
内容的提问来源于stack exchange,提问作者Nantha
相关产品推荐
相关产品推荐

