Skip to content

chore: lift up playwright prelaunch #36330

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Skn0tt
Copy link
Member

@Skn0tt Skn0tt commented Jun 16, 2025

Prep work for multiple connections to the same server. Removes Browser closing from the server, and makes sure all connections use the same Playwright instance.

@Skn0tt Skn0tt requested a review from dgozman June 16, 2025 15:28
@Skn0tt Skn0tt self-assigned this Jun 16, 2025

This comment has been minimized.

This comment has been minimized.

for (const browser of playwright.allBrowsers())
await browser.close({ reason: 'Connection terminated' });
});
this._cleanups.push(() => browser.close({ reason: 'Connection terminated' }));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While this change here makes sense, let's keep the "close all browsers upon disconnect" logic in PlaywrightServer when we are running in non-extension mode for now.

Copy link
Member Author

@Skn0tt Skn0tt Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it back to the PlaywrightConnection#onClose handler, is that what you had in mind?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, that fails all multiclient tests. Probably not what you had in mind.


onClose: async () => {
debugLogger.log('server', 'closing browsers');
if (this._preLaunchedPlaywright)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this code, but for connection.onClose() scenario as mentioned in another comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confused by this code. I thought that onClose is about the WS connection closing. But instead, it's about WS server winding down. I'm unsure if it makes sense to kill browsers that were injected via preLaunchedBrowser - reverted this change for now.

if (options.preLaunchedAndroidDevice)
this._preLaunchedPlaywright = options.preLaunchedAndroidDevice._android.attribution.playwright;
this._playwright = options.preLaunchedAndroidDevice._android.attribution.playwright;
this._playwright ??= createPlaywright({ sdkLanguage: 'javascript', isServer: true });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like both sdkLanguage and socksProxyPort options should become per-browser instead of per-playwright.

Copy link
Member Author

@Skn0tt Skn0tt Jun 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per-browser, or maybe per connection instead? That'd be a much bigger refactoring though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"connection" does not exist on the server-side that operates sdk objects. So "per browser".

@Skn0tt Skn0tt requested a review from dgozman June 17, 2025 12:15

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

73 failed
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › launchServer › should be able to reconnect to a browser @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › launchServer › should be able to connect two browsers at the same time @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › run-server › should be able to reconnect to a browser @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › run-server › should be able to connect two browsers at the same time @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/browsertype-connect.spec.ts:1027:3 › launchServer only › should be able to reconnect to a browser 12 times without warnings @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:61:1 › should connect two clients @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:119:1 › should not allow parallel js coverage and cleanup upon disconnect @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:132:1 › should not allow parallel css coverage @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:145:1 › should unpause clock @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:164:1 › should chain routes @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:232:1 › should remove exposed bindings upon disconnect @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:260:1 › should remove init scripts upon disconnect @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/multiclient.spec.ts:284:1 › should remove locator handlers upon disconnect @chromium-ubuntu-22.04-node18
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › launchServer › should be able to reconnect to a browser @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › launchServer › should be able to connect two browsers at the same time @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › run-server › should be able to reconnect to a browser @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › run-server › should be able to connect two browsers at the same time @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/browsertype-connect.spec.ts:1027:3 › launchServer only › should be able to reconnect to a browser 12 times without warnings @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:61:1 › should connect two clients @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:119:1 › should not allow parallel js coverage and cleanup upon disconnect @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:132:1 › should not allow parallel css coverage @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:145:1 › should unpause clock @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:164:1 › should chain routes @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:232:1 › should remove exposed bindings upon disconnect @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:260:1 › should remove init scripts upon disconnect @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/multiclient.spec.ts:284:1 › should remove locator handlers upon disconnect @chromium-ubuntu-22.04-node20
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › launchServer › should be able to reconnect to a browser @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › launchServer › should be able to connect two browsers at the same time @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › run-server › should be able to reconnect to a browser @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › run-server › should be able to connect two browsers at the same time @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/browsertype-connect.spec.ts:1027:3 › launchServer only › should be able to reconnect to a browser 12 times without warnings @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:61:1 › should connect two clients @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:119:1 › should not allow parallel js coverage and cleanup upon disconnect @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:132:1 › should not allow parallel css coverage @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:145:1 › should unpause clock @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:164:1 › should chain routes @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:232:1 › should remove exposed bindings upon disconnect @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:260:1 › should remove init scripts upon disconnect @chromium-ubuntu-22.04-node22
❌ [chromium-library] › library/multiclient.spec.ts:284:1 › should remove locator handlers upon disconnect @chromium-ubuntu-22.04-node22
❌ [firefox-library] › library/browsertype-connect.spec.ts:142:5 › launchServer › should be able to reconnect to a browser @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/browsertype-connect.spec.ts:199:5 › launchServer › should be able to connect two browsers at the same time @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/browsertype-connect.spec.ts:142:5 › run-server › should be able to reconnect to a browser @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/browsertype-connect.spec.ts:199:5 › run-server › should be able to connect two browsers at the same time @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/browsertype-connect.spec.ts:1027:3 › launchServer only › should be able to reconnect to a browser 12 times without warnings @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/multiclient.spec.ts:61:1 › should connect two clients @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/multiclient.spec.ts:145:1 › should unpause clock @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/multiclient.spec.ts:164:1 › should chain routes @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/multiclient.spec.ts:232:1 › should remove exposed bindings upon disconnect @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/multiclient.spec.ts:260:1 › should remove init scripts upon disconnect @firefox-ubuntu-22.04-node18
❌ [firefox-library] › library/multiclient.spec.ts:284:1 › should remove locator handlers upon disconnect @firefox-ubuntu-22.04-node18
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › launchServer › should be able to reconnect to a browser @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › launchServer › should be able to connect two browsers at the same time @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/browsertype-connect.spec.ts:142:5 › run-server › should be able to reconnect to a browser @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/browsertype-connect.spec.ts:1027:3 › launchServer only › should be able to reconnect to a browser 12 times without warnings @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:61:1 › should connect two clients @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:119:1 › should not allow parallel js coverage and cleanup upon disconnect @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:132:1 › should not allow parallel css coverage @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:145:1 › should unpause clock @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:164:1 › should chain routes @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:232:1 › should remove exposed bindings upon disconnect @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:260:1 › should remove init scripts upon disconnect @ubuntu-22.04-chromium-tip-of-tree
❌ [chromium-library] › library/multiclient.spec.ts:284:1 › should remove locator handlers upon disconnect @ubuntu-22.04-chromium-tip-of-tree
❌ [webkit-library] › library/browsertype-connect.spec.ts:142:5 › launchServer › should be able to reconnect to a browser @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/browsertype-connect.spec.ts:199:5 › launchServer › should be able to connect two browsers at the same time @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/browsertype-connect.spec.ts:142:5 › run-server › should be able to reconnect to a browser @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/browsertype-connect.spec.ts:199:5 › run-server › should be able to connect two browsers at the same time @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/browsertype-connect.spec.ts:1027:3 › launchServer only › should be able to reconnect to a browser 12 times without warnings @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/multiclient.spec.ts:61:1 › should connect two clients @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/multiclient.spec.ts:145:1 › should unpause clock @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/multiclient.spec.ts:164:1 › should chain routes @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/multiclient.spec.ts:232:1 › should remove exposed bindings upon disconnect @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/multiclient.spec.ts:260:1 › should remove init scripts upon disconnect @webkit-ubuntu-22.04-node18
❌ [webkit-library] › library/multiclient.spec.ts:284:1 › should remove locator handlers upon disconnect @webkit-ubuntu-22.04-node18

7 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:986:7 › cli codegen › should not throw csp directive violation errors @firefox-ubuntu-22.04-node18
⚠️ [chromium-library] › library/browsertype-connect.spec.ts:199:5 › run-server › should be able to connect two browsers at the same time @ubuntu-22.04-chromium-tip-of-tree
⚠️ [webkit-library] › library/browsercontext-pages.spec.ts:82:3 › should click the button with offset with page scale @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/browsercontext-viewport-mobile.spec.ts:97:5 › mobile viewport › should fire orientationchange event @webkit-ubuntu-22.04-node18
⚠️ [webkit-library] › library/screenshot.spec.ts:66:14 › page screenshot › should work with a mobile viewport and fullPage @webkit-ubuntu-22.04-node18
⚠️ [webkit-page] › page/page-screenshot.spec.ts:345:5 › page screenshot › should work while navigating @webkit-ubuntu-22.04-node18
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:145:5 › should watch all @windows-latest-node18-1

39341 passed, 822 skipped
✔️✔️✔️

Merge workflow run.

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

Successfully merging this pull request may close these issues.

2 participants