在browsermob-proxy-api模块中使用 addURLWhiteList 时出现服务器错误:500。我使用的是 Node JS 和量角器。我想仅从相关 URL 生成信息,因为如果所有第三方服务流量也包含在 HAR 文件中,生成的 HAR 文件的大小将变得太大。这是我的代码:-
(conf.js)
/* global exports, require, jasmine, browser */
var Proxy = require('browsermob-proxy-api'),
Q = require('q');
exports.config = {
chromeOnly: true,
capabilities: {
browserName: 'chrome',
proxy: {
proxyType: 'manual',
httpProxy: 'localhost:8888',
sslProxy: 'localhost:8888'
}
},
specs: ['abcd'],
onPrepare: function () {
(spec.js)
/* global describe, beforeEach, afterEach, it, console, browser, element, expect
*/
var fs = require('fs');
var date = new Date();
describe('Angular Homepage', function () {
beforeEach(function (done) {
console.log('beforeEach');
console.log('browser.params.proxy', browser.params.proxy);
console.log('browser.params.proxyData', browser.params.proxyData);
browser.params.proxy.createHAR(8888, { 'initialPageRef': 'foo', 'captureContent': 'true' });
browser.params.proxy.addURLWhiteList(8888, 'http://abcd.com',function (err) {
if(err) {
return console.log("white list error" + err);
}
});
});
afterEach(function (done) {
console.log('afterEach');
browser.params.proxy.getHAR(8888, function (err, harData) {
// console.log('harData', harData);
fs.writeFile("C:\Protractor\p1" + Date.now() + ".har", harData, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
});
done();
});
});
现在,当我运行此代码时,我从 addURLWhiteList 方法收到此错误。
onPrepare
data { port: 8888 }
arguments { '0': { port: 8888 } }
Started
beforeEach
browser.params.proxy { host: 'localhost',
port: 8080,
proxyPort: null,
selHost: 'localhost',
selPort: 4444,
downstreamKbps: undefined,
upstreamKbps: undefined,
latency: undefined }
browser.params.proxyData { port: 8888 }
white list errorError: Error from server: 500
[INFO 2018-04-10T10:52:32,758 org.littleshoot.proxy.impl.DefaultHttpProxyServer] (qtp864852424-16) Proxy started at address: /0:0:0:0:0:0:0:0:8888
[WARN 2018-04-10T10:52:32,975 org.eclipse.jetty.util.log] (qtp864852424-21) /proxy/8888/whitelist com.google.sitebricks.routing.EventDispatchException: Exception [NullPointerException - "null"] thrown by event method [public com.google.sitebricks.headless.Reply net.lightbody.bmp.proxy.bricks.ProxyResource.whitelist(int,com.google.sitebricks.headless.Request)]
at net.lightbody.bmp.proxy.bricks.ProxyResource.whitelist(ProxyResource.java:243)
(See below for entire trace.)
at com.google.sitebricks.routing.DefaultPageBook$MethodTuple.call(DefaultPageBook.java:830) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.routing.DefaultPageBook$MethodTuple.call(DefaultPageBook.java:805) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.routing.DefaultPageBook$PageTuple.callAction(DefaultPageBook.java:624) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.routing.DefaultPageBook$PageTuple.doMethod(DefaultPageBook.java:603) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.routing.WidgetRoutingDispatcher.fireEvent(WidgetRoutingDispatcher.java:171) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.routing.WidgetRoutingDispatcher.bindAndReply(WidgetRoutingDispatcher.java:102) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.routing.WidgetRoutingDispatcher.dispatch(WidgetRoutingDispatcher.java:88) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.DebugModeRoutingDispatcher.dispatch(DebugModeRoutingDispatcher.java:56) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.SitebricksFilter.doFilter(SitebricksFilter.java:62) ~[browsermob-dist-2.1.4.jar:?]
at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163) ~[browsermob-dist-2.1.4.jar:?]
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58) ~[browsermob-dist-2.1.4.jar:?]
at com.google.sitebricks.HiddenMethodFilter.doFilter(HiddenMethodFilter.java:70) ~[browsermob-dist-2.1.4.jar:?]
at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:163) ~[browsermob-dist-2.1.4.jar:?]
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58) ~[browsermob-dist-2.1.4.jar:?]
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118) ~[browsermob-dist-2.1.4.jar:?]
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113) ~[browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1323) ~[browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:474) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:224) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:935) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:404) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:184) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:870) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.Server.handle(Server.java:346) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:596) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.HttpConnection$RequestHandler.content(HttpConnection.java:1068) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:807) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:220) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:426) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:520) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40) [browsermob-dist-2.1.4.jar:?]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:528) [browsermob-dist-2.1.4.jar:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_161]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_161]
at com.google.sitebricks.routing.DefaultPageBook$MethodTuple.call(DefaultPageBook.java:820) ~[browsermob-dist-2.1.4.jar:?]
... 34 more
Caused by: java.lang.NullPointerException
at net.lightbody.bmp.proxy.bricks.ProxyResource.whitelist(ProxyResource.java:243) ~[browsermob-dist-2.1.4.jar:?]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_161]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_161]
at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_161]
at com.google.sitebricks.routing.DefaultPageBook$MethodTuple.call(DefaultPageBook.java:820) ~[browsermob-dist-2.1.4.jar:?]
... 34 more
[WARN 2018-04-10T10:52:37,154 net.lightbody.bmp.filters.ServerResponseCaptureFilter] (LittleProxy-0-ProxyToServerWorker-5) Cannot decode unsupported content encoding type br
[WARN 2018-04-10T10:52:37,158 net.lightbody.bmp.filters.HarCaptureFilter] (LittleProxy-0-ProxyToServerWorker-5) Unable to decompress content with encoding: br. Contents will be encoded as base64 binary data.
[WARN 2018-04-10T10:52:37,448 net.lightbody.bmp.filters.HarCaptureFilter] (LittleProxy-0-ProxyToServerWorker-4) No content type specified in response from
[WARN 2018-04-10T10:52:53,337 net.lightbody.bmp.filters.ServerResponseCaptureFilter] (LittleProxy-0-ProxyToServerWorker-5) Cannot decode unsupported content encoding type br
[WARN 2018-04-10T10:52:53,347 net.lightbody.bmp.filters.HarCaptureFilter] (LittleProxy-0-ProxyToServerWorker-5) Unable to decompress content with encoding: br. Contents will be encoded as base64 binary data.
[WARN 2018-04-10T10:52:57,194 net.lightbody.bmp.filters.HarCaptureFilter] (LittleProxy-0-ProxyToServerWorker-0) No content type specified in response from http://scripts.kissmetrics.com/db61c23bf4bcf1cb3d69837064a4f2ccc6a6c5c3.2.js. Content will be treated as application/octet-stream
我是新手。谁能告诉我如何解决这个错误?