question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Attaching playwright to an existing browser window?

See original GitHub issue

Hey,

First of all thank you for this wonderful library ❤️

I’m working on a feature for playwright recorder to let you more easily run playwright tests from the browser.

I want to attach playwright to a context that is already running (opened with ChromeDriver if that matters):

    const browser = await playwright.chromium.connect({
        wsEndpoint: cdpUrl,
    });
    const contexts = browser.contexts(); // empty

    // how do I get the existing already open pages?

    const context = await browser.newContext({viewport: null })
    const pages = await context.pages(); // empty

I checked puppeteer and it was easy to get working like this:

    const browser = await puppeteer.connect({
        browserWSEndpoint: cdpUrl,
        defaultViewport: null, // disable puppeteer resize
        product: 'chrome', 
    });
    const pages = await browser.pages();

    const page = last(pages);

Is there an official method to obtain existing browser contexts?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:6
  • Comments:44 (30 by maintainers)

github_iconTop GitHub Comments

13reactions
pavelfeldmancommented, Jun 28, 2020

I’ll tentatively close this as won’t fix. It is essential for Playwright to be able to run the browser in the controlled environment. There are a lot of good hints here on how this can be worked around, but it is unlikely that they get into the official Playwright API.

10reactions
benjamingrcommented, Apr 25, 2020

I’ll try to describe the use case:

  • Imagine I already have a large codebase written in Selenium.
  • I would like to author new features with playwright instead or to leverage a library written in playwright.
  • When launching the selenium test I get the debugger URL from ChromeDriver after launching my browser and connect playwright to it.
  • I can now author new features with Playwright - and for example port the function that logs me into the website being tested from selenium to playwright.

The feature I’m asking for enables mixing and matching playwright with selenium or puppeteer more easily. I specifically need it to run the playwright playground (mentioned above) on tabs controlled inside ChromeDriver

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Ways of Attaching to Existing Browsers in Web Automation
We are introducing the browser attaching method for different automation libraries here, containing Selenium, Playwright and Clicknium.
Read more >
Is there a way to connect to my existing browser session using ...
You can use puppeteer-core or playwright to control your existing browser installation, for example Chrome, and then use the existing user data ...
Read more >
Playwright allows you to connect to existing browser instances ...
Playwright allows you to connect to existing browser instances, but it currently requires you to get the “debug URL” of the browser instance ......
Read more >
How to start with Playwright Debugging | BrowserStack
A step-by-step tutorial to perform Playwright Debugging and help you choose a suitable option to deliver a high-quality web application.
Read more >
Playwright: Launching Cross-Browser Automation to the Stars
This problem was not solved until the last weeks, when we added parallel Playwright tests execution support to Moon — a browser automation ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found