fix(connectOverCDP): send custom headers in /json/version request (#29408)

Fixes #29403.
This commit is contained in:
Dmitry Gozman 2024-02-07 17:41:21 -08:00 committed by GitHub
parent 6b37a706db
commit 3abd7c808e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 4 deletions

View File

@ -82,7 +82,7 @@ export class Chromium extends BrowserType {
const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);
const wsEndpoint = await urlToWSEndpoint(progress, endpointURL);
const wsEndpoint = await urlToWSEndpoint(progress, endpointURL, headersMap);
progress.throwIfAborted();
const chromeTransport = await WebSocketTransport.connect(progress, wsEndpoint, headersMap);
@ -351,13 +351,14 @@ export class Chromium extends BrowserType {
}
}
async function urlToWSEndpoint(progress: Progress, endpointURL: string) {
async function urlToWSEndpoint(progress: Progress, endpointURL: string, headers: { [key: string]: string; }) {
if (endpointURL.startsWith('ws'))
return endpointURL;
progress.log(`<ws preparing> retrieving websocket url from ${endpointURL}`);
const httpURL = endpointURL.endsWith('/') ? `${endpointURL}json/version/` : `${endpointURL}/json/version/`;
const json = await fetchData({
url: httpURL,
headers,
}, async (_, resp) => new Error(`Unexpected status ${resp.statusCode} when connecting to ${httpURL}.\n` +
`This does not look like a DevTools server, try connecting via ws://.`)
);

View File

@ -256,9 +256,9 @@ test('should send extra headers with connect request', async ({ browserType, ser
}
{
const [request] = await Promise.all([
server.waitForWebSocketConnectionRequest(),
server.waitForRequest('/json/version/'),
browserType.connectOverCDP({
endpointURL: `ws://localhost:${server.PORT}/ws`,
endpointURL: `http://localhost:${server.PORT}`,
headers: {
'User-Agent': 'Playwright',
'foo': 'bar',