playwright-java icon indicating copy to clipboard operation
playwright-java copied to clipboard

Failed to start playwright through cglib agent with error

Open zengchao304 opened this issue 2 years ago • 1 comments

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: issue1 issue2

I had set PLAYWRIGHT_JAVA_SRC environment variable. issue3

It seems that the cglib proxy automatically generates proxy classes, and starting playwright is not supported. Because a '' string cannot pass the verification of isinvalidpathchar method in windowspathparser class

Is there any good way to solve this problem? Looking forward to your reply!Thanks!

zengchao304 avatar Aug 03 '22 07:08 zengchao304

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.

yury-s avatar Aug 03 '22 16:08 yury-s

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.

yury-s avatar Aug 17 '22 22:08 yury-s