browsermob-proxy icon indicating copy to clipboard operation
browsermob-proxy copied to clipboard

browsermob Cannot intercept Ajax request

Open willianfu opened this issue 4 years ago • 1 comments

I'm very sorry to disturb you

version:2.1.5

In addition to Ajax, other requests can be intercepted normally. i don't know reason, I hope you can answer for me. Thank you very much

this is my code:

 System.setProperty("webdriver.chrome.driver", "D:\\java\\chromedriver\\chromedriver.exe");
    //BrowserMobProxy proxy = new BrowserMobProxyServer();
    BrowserMobProxy proxy = new ProxyServer();
    proxy.start(0);
    proxy.newHar("localhost");
    proxy.enableHarCaptureTypes(CaptureType.REQUEST_HEADERS, CaptureType.REQUEST_CONTENT,
            CaptureType.RESPONSE_CONTENT, CaptureType.RESPONSE_HEADERS);

    System.out.println("启动在端口: " + proxy.getPort());

    ((LegacyProxyServer)proxy).addRequestInterceptor(new RequestInterceptor() {
        @Override
        public void process(BrowserMobHttpRequest request, Har har) {
            System.out.println(request.getMethod().getURI().toString());
            request.getMethod().removeHeaders("User-Agent");
            request.getMethod().addHeader("User-Agent", "Bananabot/1.0");
        }
    });

 /**
   proxy.addRequestFilter((httpRequest, httpMessageContents, httpMessageInfo) -> {
      if (httpMessageInfo.getOriginalUrl().contains("pur/channel")){
          System.out.println("request -------> " + httpMessageContents.getTextContents());
      }
      return null;
  });
**/
  Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
  DesiredCapabilities capabilities = new DesiredCapabilities();
  capabilities.setAcceptInsecureCerts(true);
  capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
  capabilities.setJavascriptEnabled(true);

  ChromeOptions options = new ChromeOptions();
  options.merge(capabilities);
  ChromeDriver driver = new ChromeDriver(options);
  driver.manage().window().setSize(new Dimension(1366, 700));
  driver.get("http://localhost:8086/doc.html");

willianfu avatar Dec 24 '20 02:12 willianfu

I met the same problem, I don't know how to deal with it。I hope the author can help me。

sijunji avatar Jan 02 '21 23:01 sijunji