fix(launchServer): return precise wsAddress

This commit is contained in:
Max Schmitt 2024-05-27 11:29:45 +02:00
parent a7599ad509
commit c14084be84
3 changed files with 6 additions and 7 deletions

View file

@ -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.

View file

@ -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);
});

View file

@ -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;