Chrome 使用 browsermob-proxy 的浏览器证书不受信任问题
Chrome browser certificate is not trusted issue using browsermob-proxy
有没有办法让chrome忽略使用browsermob-proxy
导致的无效证书
我使用 google.com 只是出于示例原因,在实际情况下我需要提供凭据和登录,无效的证书阻止我继续。
please note here that the proxy is working perfectly and after i used all args to ignore the certificate issue
https://i.stack.imgur.com/dG4Vl.png
import java.io.File;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.testng.annotations.Test;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.core.har.Har;
public class Proxytest4 {
WebDriver driver = null;
BrowserMobProxy proxy = null;
@Test
public void actionLaunchRegistrationPage() throws Exception {
System.setProperty("webdriver.chrome.driver", "/Users/path/chromedriver");
System.setProperty("webdriver.chrome.logfile", "/Users/path/hromedriver_issue.log");
proxy = new BrowserMobProxyServer();
proxy.setTrustAllServers(true);
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=" + seleniumProxy.getHttpProxy());
options.addArguments("--no-sandbox");
options.addArguments("--start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("disable-gpu");
options.addArguments("window-size=1920,1080");
// options.setAcceptInsecureCerts(true);
options.addArguments("--allow-insecure-localhost");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--allow-running-insecure-content");
// DesiredCapabilities cap = DesiredCapabilities.chrome();
// cap.acceptInsecureCerts();
// cap.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
// cap.setCapability (CapabilityType.ACCEPT_INSECURE_CERTS, true);
// cap.setCapability(ChromeOptions.CAPABILITY, options);
// options.setAcceptInsecureCerts(true);
// options.merge(cap);
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
// driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), cap);
driver = new ChromeDriver(options);
// create a new HAR with the label "yahoo.com"
proxy.newHar("https://www.google.com/");
driver.get("https://www.google.com/");
// get the HAR data
Har har = proxy.getHar();
// Writing Har to file
har.getLog().toString();
har.writeTo(new File("/Users/path/HAR.txt"));
// driver.quit();
// browserStackLocal.stop();
proxy.stop();
}
}
我认为--disable-web-security
是您想要的选项。
修复如下:
1- 从下面 link 下载 browsermob-proxy 证书:
https://github.com/lightbody/browsermob-proxy/blob/master/browsermob-core/src/main/resources/sslSupport/ca-certificate-rsa.cer
2- 在 OS X 中打开钥匙串访问实用程序。
- Select左边的系统选项。单击锁定图标
左上角以启用更改。
enter image description here
- 在左下方,select 证书选项。
enter image description here
- 将你复制到桌面的证书拖到列表中
证书。将 localhost 添加到系统钥匙串后,
双击它再次打开它。展开信任部分并为
第一个选项,选择始终信任。
enter image description here
有没有办法让chrome忽略使用browsermob-proxy
导致的无效证书我使用 google.com 只是出于示例原因,在实际情况下我需要提供凭据和登录,无效的证书阻止我继续。
please note here that the proxy is working perfectly and after i used all args to ignore the certificate issue https://i.stack.imgur.com/dG4Vl.png
import java.io.File;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.testng.annotations.Test;
import net.lightbody.bmp.BrowserMobProxy;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.core.har.Har;
public class Proxytest4 {
WebDriver driver = null;
BrowserMobProxy proxy = null;
@Test
public void actionLaunchRegistrationPage() throws Exception {
System.setProperty("webdriver.chrome.driver", "/Users/path/chromedriver");
System.setProperty("webdriver.chrome.logfile", "/Users/path/hromedriver_issue.log");
proxy = new BrowserMobProxyServer();
proxy.setTrustAllServers(true);
proxy.start(0);
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
ChromeOptions options = new ChromeOptions();
options.addArguments("--proxy-server=" + seleniumProxy.getHttpProxy());
options.addArguments("--no-sandbox");
options.addArguments("--start-maximized");
options.addArguments("--disable-extensions");
options.addArguments("disable-gpu");
options.addArguments("window-size=1920,1080");
// options.setAcceptInsecureCerts(true);
options.addArguments("--allow-insecure-localhost");
options.addArguments("--ignore-certificate-errors");
options.addArguments("--allow-running-insecure-content");
// DesiredCapabilities cap = DesiredCapabilities.chrome();
// cap.acceptInsecureCerts();
// cap.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true);
// cap.setCapability (CapabilityType.ACCEPT_INSECURE_CERTS, true);
// cap.setCapability(ChromeOptions.CAPABILITY, options);
// options.setAcceptInsecureCerts(true);
// options.merge(cap);
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
// driver = new RemoteWebDriver(new URL("http://127.0.0.1:9515"), cap);
driver = new ChromeDriver(options);
// create a new HAR with the label "yahoo.com"
proxy.newHar("https://www.google.com/");
driver.get("https://www.google.com/");
// get the HAR data
Har har = proxy.getHar();
// Writing Har to file
har.getLog().toString();
har.writeTo(new File("/Users/path/HAR.txt"));
// driver.quit();
// browserStackLocal.stop();
proxy.stop();
}
}
我认为--disable-web-security
是您想要的选项。
修复如下:
1- 从下面 link 下载 browsermob-proxy 证书: https://github.com/lightbody/browsermob-proxy/blob/master/browsermob-core/src/main/resources/sslSupport/ca-certificate-rsa.cer
2- 在 OS X 中打开钥匙串访问实用程序。
- Select左边的系统选项。单击锁定图标 左上角以启用更改。
enter image description here
- 在左下方,select 证书选项。
enter image description here
- 将你复制到桌面的证书拖到列表中 证书。将 localhost 添加到系统钥匙串后, 双击它再次打开它。展开信任部分并为 第一个选项,选择始终信任。
enter image description here