playwright-java
playwright-java copied to clipboard
Failed to start playwright through cglib agent with error
Hello! This is a great project, and I appreciate it very much! Context:
Playwright Version: 1.23 Operating System: Windows 10 Browser: Chromium
Code Snippet
public class Example {
public void doSomething(){
try (Playwright playwright = Playwright.create()) {
Browser browser = playwright.chromium().launch(new BrowserType.LaunchOptions().setHeadless(false).setArgs(
Arrays.asList("--disable-setuid-sandbox")));
BrowserContext context = browser.newContext();
// Open new page
Page page = context.newPage();
// Go to https://www.wikipedia.org/
page.navigate("https://www.wikipedia.org/",
new Page.NavigateOptions().setWaitUntil(WaitUntilState.NETWORKIDLE));
String userAgent = (String)page.evaluate("navigator.userAgent");
}
}
}
public class MyCglib implements MethodInterceptor {
@Override
public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
final Object o1 = methodProxy.invokeSuper(o, objects);
return o1;
}
}
public class PlaywrightTestWithCglib {
public static void main(String[] args) {
final Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Example.class);
enhancer.setCallback(new MyCglib());
final Example example = (Example)enhancer.create();
example.doSomething();
System.out.println(example.getClass());
}
}
Describe the bug currently,I want to intercept and start playwright through cglib agent, but I get the following error:
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.CommandLineWrapper.main(CommandLineWrapper.java:64)
Caused by: java.nio.file.InvalidPathException: Illegal char <<> at index 0: <generated>
The following picture is the suspicious place I traced during debugging:
I had set PLAYWRIGHT_JAVA_SRC environment variable.
It seems that the cglib proxy automatically generates proxy classes, and starting playwright is not supported. Because a '
Is there any good way to solve this problem? Looking forward to your reply!Thanks!
It looks like a cglib problem rather than playwright. I don't know much about how they work but as you mentioned they probably generate proxies for all playwright classes whereas I assume you'd need them only for those in the public API, so perhaps you can configure cglib to limit the scope where it applies? Also seeing full stack trace and knowing more about what you are trying to achieve could help us provide better advice to you.
Closing as part of the triage process since it seemed stale. Please create a new issue with a detailed reproducible if you still face the issue.