Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Browser object not available when a page is launched using launchPersistentContextOptions #1576

Closed
srichhar opened this issue May 14, 2024 · 2 comments

Comments

@srichhar
Copy link

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
@mxschmitt
Copy link
Member

As per the documentation browser() is null when launching a persistent context.

@mxschmitt
Copy link
Member

Closing as per above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants