playwright-java
playwright-java copied to clipboard
[Bug]: Browser object not available when a page is launched using launchPersistentContextOptions
Version
1.43.0
Steps to reproduce
If we run the below code in a main function:
try (Playwright playwright = Playwright.create()) {
LaunchPersistentContextOptions launchPersistentContextOptions =
new BrowserType.LaunchPersistentContextOptions();
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch();
BrowserContext context = browser.browserType()
.launchPersistentContext(Paths.get("userprofiles"), launchPersistentContextOptions);
com.microsoft.playwright.Page pageMethod1 = context.newPage();
pageMethod1.navigate("https://google.com");
log.debug("Is browser object available with launchPersistentContextOptions? : {}", pageMethod1.context().browser()!=null);
}
try (Playwright playwright = Playwright.create()) {
BrowserType chromium = playwright.chromium();
Browser browser = chromium.launch();
BrowserContext context = browser.newContext();
com.microsoft.playwright.Page pageMethod2 = context.newPage();
pageMethod2.navigate("https://google.com");
log.debug("Is browser object available with newContext? : {}", pageMethod2.context().browser()!=null);
}
I get output as:
Is browser object available with launchPersistentContextOptions? : false
Is browser object available with newContext? : true
Expected behavior
Is browser object available with launchPersistentContextOptions? : true
Is browser object available with newContext? : true
Actual behavior
I want to get the executable path and user data directory from the page object. According to API documentation, I should have got it using pageMethod1.context().browser().browserType().executablePath()
when the page is launched using launchPersistentContextOptions. However, pageMethod1.context().browser() is always null.
Any help here would be appreciated.
Additional context
No response
Environment
- Browser: Chromium
- Operating System: macOS Sonoma
- Java Version: Java 19
As per the documentation browser()
is null when launching a persistent context.
Closing as per above.