Skip to content

fix(launchServer): return precise wsAddress #31026

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

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/src/api/class-browserserver.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,3 @@ Browser websocket url.

Browser websocket endpoint which can be used as an argument to [`method: BrowserType.connect`] to establish connection
to the browser.

Note that if the listen `host` option in `launchServer` options is not specified, localhost will be output anyway, even if the actual listening address is an unspecified address.
8 changes: 6 additions & 2 deletions packages/playwright-core/src/utils/wsServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,12 @@ export class WSServer {
reject(new Error('Could not bind server socket'));
return;
}
const wsEndpoint = typeof address === 'string' ? `${address}${path}` : `ws://${hostname || 'localhost'}:${address.port}${path}`;
resolve(wsEndpoint);
if (typeof address === 'string') {
resolve(`${address}${path}`);
return;
}
const resolvedHost = address.family === 'IPv4' ? address.address : `[${address.address}]`;
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Shouldn't this be hostname when it is defined?
  • I am afraid this could accidentally break someone expecting localhost in the address and getting 127.0.0.1 or [::1] instead. Should we wait for a bug report?

resolve(`ws://${resolvedHost}:${address.port}${path}`);
}).on('error', reject);
});

Expand Down
3 changes: 0 additions & 3 deletions packages/playwright-core/types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17215,9 +17215,6 @@ export interface BrowserServer {
* Browser websocket endpoint which can be used as an argument to
* [browserType.connect(wsEndpoint[, options])](https://playwright.dev/docs/api/class-browsertype#browser-type-connect)
* to establish connection to the browser.
*
* Note that if the listen `host` option in `launchServer` options is not specified, localhost will be output anyway,
* even if the actual listening address is an unspecified address.
*/
wsEndpoint(): string;

Expand Down
Loading