You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Electron应用启动后瞬间消失及ChromeDriver版本匹配问题求助

问题描述

尝试通过Chromium启动基于Electron的应用,应用启动后瞬间消失,无法进行后续操作。控制台抛出org.openqa.selenium.SessionNotCreatedException异常,提示当前ChromeDriver仅支持Chrome 110版本,但检测到的浏览器版本为100.0.4896.143。当前使用的本地Chromium版本为110.0.5481.78,Chrome浏览器版本为110.0.5481.77,且未找到对应Chromium版本110.0.5481.78的Electron版本。

代码片段

ChromeOptions options = new ChromeOptions();
options.setBinary("C://folder//folderpath//executableFilePath.exe");            
options.setCapability("chromeOptions", options);
WebDriver weBdriver = new ChromeDriver(options);

控制台日志

org.openqa.selenium.SessionNotCreatedException: session not created: This version of ChromeDriver only supports Chrome version 110
        Current browser version is 100.0.4896.143 with binary path C:\Program Files\file\file.exe
        Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
        System info: host: '', ip: '', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.5'
        Driver info: driver.version: ChromeDriver
        remote stacktrace: Backtrace:
            Cr_z_deflate [0x00007FF6EB3BACE2+123234]
            (No symbol) [0x00007FF6EB316F82]
            (No symbol) [0x00007FF6EB1C772D]
            (No symbol) [0x00007FF6EB1F0840]
            (No symbol) [0x00007FF6EB1EB5F4]
            (No symbol) [0x00007FF6EB1E8F79]
            (No symbol) [0x00007FF6EB2251EA]
            (No symbol) [0x00007FF6EB21D413]
            (No symbol) [0x00007FF6EB1F329E]
            (No symbol) [0x00007FF6EB1F454E]
            GetHandleVerifier [0x00007FF6EB725030+3484560]
            GetHandleVerifier [0x00007FF6EB76197B+3732699]
            GetHandleVerifier [0x00007FF6EB765405+3747685]
            GetHandleVerifier [0x00007FF6EB496EEA+805450]
            (No symbol) [0x00007FF6EB323643]
            (No symbol) [0x00007FF6EB32BC44]
            (No symbol) [0x00007FF6EB32BD74]
            (No symbol) [0x00007FF6EB3385FD]
            BaseThreadInitThunk [0x00007FF9D6A87034+20]
            RtlUserThreadStart [0x00007FF9D7802651+33]
        
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
            at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
            at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
            at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
            at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
            at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
            at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
            at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
            at java.base/java.util.Spliterators$ArraySpliterator.tryAdvance(Spliterators.java:1002)
            at java.base/java.util.stream.ReferencePipeline.forEachWithCancel(ReferencePipeline.java:129)
            at java.base/java.util.stream.AbstractPipeline.copyIntoWithCancel(AbstractPipeline.java:527)
            at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:513)
            at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
            at java.base/java.util.stream.FindOps$FindOp.evaluateSequential(FindOps.java:150)
            at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
            at java.base/java.util.stream.ReferencePipeline.findFirst(ReferencePipeline.java:647)
            at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
            at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:74)
            at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:136)
            at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
            at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
            at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:213)
            at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
            at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:181)
            at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:168)
            at org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:157)

解决步骤

1. 修复版本匹配异常

日志显示检测到的浏览器版本是100.0.4896.143,说明你的Electron应用内置的Chromium版本为100,而非本地安装的110版本:

  • 下载对应100.0.4896.x版本的ChromeDriver,替换当前使用的驱动文件;
  • 确认Electron应用的实际Chromium版本:可通过打开应用开发者工具,在控制台输入process.versions.chrome查看,或查阅应用的打包配置/发布文档。

2. 调整启动参数防止应用瞬间关闭

修改ChromeOptions配置,添加Electron专属启动参数,并修正capability键名:

ChromeOptions options = new ChromeOptions();
// 指定Electron应用路径
options.setBinary("C://folder//folderpath//executableFilePath.exe");
// 添加参数避免应用自动关闭
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
// 使用新版Selenium兼容的capability键名
options.setCapability("goog:chromeOptions", options);
WebDriver weBdriver = new ChromeDriver(options);

3. 匹配Electron与Chromium版本

若需使用110.x版本的Chromium,需找到对应版本的Electron:

  • Electron版本与内置Chromium版本绑定,可通过Electron版本说明文档,找到内置Chromium为110.x的Electron版本,再更换或重新打包应用。

内容的提问来源于stack exchange,提问作者sowmiya abi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 01:13:59