diff --git a/docs/src/api/class-browserserver.md b/docs/src/api/class-browserserver.md index 0de5c1228b..21f318a70a 100644 --- a/docs/src/api/class-browserserver.md +++ b/docs/src/api/class-browserserver.md @@ -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. diff --git a/packages/playwright-core/src/utils/wsServer.ts b/packages/playwright-core/src/utils/wsServer.ts index 63c0ed1fed..6e90a4fbb0 100644 --- a/packages/playwright-core/src/utils/wsServer.ts +++ b/packages/playwright-core/src/utils/wsServer.ts @@ -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}]`; + resolve(`ws://${resolvedHost}:${address.port}${path}`); }).on('error', reject); }); diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 54d79f9ca1..fea32c2fad 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -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;