错误日志信息:
org.openqa.selenium.WebDriverException: unknown error: cannot process extension #1
from unknown error: cannot read manifest
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 1.18 seconds
最近selenium爬虫时打开给chrome时添加插件突然报这个错误,折腾了好久,最后终于知道怎么回事,
原来是文件打zip包时不注意多打了一层!!!
我的插件是代理插件:proxy.zip,正常其中应该直接包含两个文件,background.js和manifest.json文件,但是在打包的时候使用右键直接打包成zip文件,结果导致,proxy.zip下面第一层是文件夹proxy,第二层才是我的background.js和manifest.json文件,但是代码中加载插件的时候是直接找的压缩包下面第一层的内容,于是找不到我的background.js和manifest.json文件,因此就报如下错误:
unknown error: cannot read manifest
(我的其中一个文件名为manifest.json,你的可能略有不同),总上所述也就是,你的文件路径不对,请注意检查打包后的文件路径,你很可能多打了一层文件夹,在此写入,希望能对广大网友有所帮助!
我在代码中加载方式为:
//使用代理
if (useProxy) {
//使用代理插件动态切换代理
chromeOptions.addExtensions(new File("D:\\proxy.zip"));
}