Skip to content

[Feature] Allow reconnecting to page in a separate processes #1709

@jperl

Description

@jperl

Use Case: I need to connect to an existing page created in another process to create an end-to-end test.

The way I do this right now is by using launchServer in the first process and sending the wsEndpoint and page._delegate._targetId to the second process. Then I create a WebSocket manually in the second process that uses Target.attachToTarget to connect to the page.

Feature Request:

  1. Expose page.targetId()
  2. Allow passing targetId to browser.newBrowserCDPSession(targetId?: string);

Proposed Usage:

Process A.

const server = await playwright.chromium.launchServer();

const browser = await playwright.chromium.connect({
  wsEndpoint: server.wsEndpoint(),
});

const context = await browser.newContext();
const page = await context.newPage();

sendToProcessB({ 
  targetId: page.targetId(),
  wsEndpoint,
})

Process B.

const { targetId, wsEndpoint } = receiveFromProcessA();

const browser = await playwright.chromium.connect({ wsEndpoint });

const session = await browser.newBrowserCDPSession(targetId);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions