I am using browsermobproxy and getting lots of errors that I don't want to deal with.
Is there a way to get a site's HAR file without using browsermobproxy?
If anyone's interested, here's the error I get from server.log
Running BrowserMob Proxy using LittleProxy implementation. To revert to the legacy implementation, run the proxy with the command-line option '--use-littleproxy false'.
Exception in thread "main" com.google.inject.internal.util.$ComputationException: java.lang.ExceptionInInitializerError
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:553)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:419)
at com.google.inject.internal.util.$CustomConcurrentHashMap$ComputingImpl.get(CustomConcurrentHashMap.java:2041)
at com.google.inject.internal.FailableCache.get(FailableCache.java:50)
at com.google.inject.internal.ConstructorInjectorStore.get(ConstructorInjectorStore.java:49)
at com.google.inject.internal.ConstructorBindingImpl.initialize(ConstructorBindingImpl.java:125)
at com.google.inject.internal.InjectorImpl.initializeBinding(InjectorImpl.java:507)
at com.google.inject.internal.AbstractBindingProcessor$Processor$1.run(AbstractBindingProcessor.java:159)
at com.google.inject.internal.ProcessedBindingData.initializeBindings(ProcessedBindingData.java:44)
at com.google.inject.internal.InternalInjectorCreator.initializeStatically(InternalInjectorCreator.java:122)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:106)
at com.google.inject.Guice.createInjector(Guice.java:95)
at com.google.inject.Guice.createInjector(Guice.java:72)
at com.google.inject.Guice.createInjector(Guice.java:62)
at net.lightbody.bmp.proxy.Main.main(Main.java:47)
Caused by: java.lang.ExceptionInInitializerError
at com.google.inject.internal.cglib.reflect.$FastClassEmitter.<init>(FastClassEmitter.java:67)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.generateClass(FastClass.java:72)
at com.google.inject.internal.cglib.core.$DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
at com.google.inject.internal.cglib.core.$AbstractClassGenerator.create(AbstractClassGenerator.java:216)
at com.google.inject.internal.cglib.reflect.$FastClass$Generator.create(FastClass.java:64)
at com.google.inject.internal.BytecodeGen.newFastClass(BytecodeGen.java:207)
at com.google.inject.internal.DefaultConstructionProxyFactory.create(DefaultConstructionProxyFactory.java:53)
at com.google.inject.internal.ProxyFactory.create(ProxyFactory.java:153)
at com.google.inject.internal.ConstructorInjectorStore.createConstructor(ConstructorInjectorStore.java:89)
at com.google.inject.internal.ConstructorInjectorStore.access$000(ConstructorInjectorStore.java:28)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:36)
at com.google.inject.internal.ConstructorInjectorStore$1.create(ConstructorInjectorStore.java:32)
at com.google.inject.internal.FailableCache$1.apply(FailableCache.java:39)
at com.google.inject.internal.util.$MapMaker$StrategyImpl.compute(MapMaker.java:549)
... 14 more
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @1593948d
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
at com.google.inject.internal.cglib.core.$ReflectUtils$2.run(ReflectUtils.java:56)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at com.google.inject.internal.cglib.core.$ReflectUtils.<clinit>(ReflectUtils.java:46)
... 28 more
And here's my code:
from browsermobproxy import Server
server = Server("C:\\Users\\USER\\Desktop\\har_export\\browsermob-proxy-2.1.4\\bin\\browsermob-proxy.bat")
server.start()
proxy = server.create_proxy()
from selenium import webdriver
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
proxy.new_har("google")
driver.get("http://www.google.co.in")
proxy.har # returns a HAR JSON blob
server.stop()
driver.quit()
Any suggestions/solutions would be appreciated.
CodePudding user response:
I believe you are running your browsermob proxy under the latest version of JRE. Since version 16 there are some limitation introduced to the refelction mechanism that make the code that used to work in previous versions not working any more.
So the easiest solution would be downgrade your JRE. According to this thread, JRE 11 would work for you.