fix(connectOverCDP): send custom headers in /json/version request (#29408)
Fixes #29403.
This commit is contained in:
parent
6b37a706db
commit
3abd7c808e
|
|
@ -82,7 +82,7 @@ export class Chromium extends BrowserType {
|
||||||
|
|
||||||
const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);
|
const artifactsDir = await fs.promises.mkdtemp(ARTIFACTS_FOLDER);
|
||||||
|
|
||||||
const wsEndpoint = await urlToWSEndpoint(progress, endpointURL);
|
const wsEndpoint = await urlToWSEndpoint(progress, endpointURL, headersMap);
|
||||||
progress.throwIfAborted();
|
progress.throwIfAborted();
|
||||||
|
|
||||||
const chromeTransport = await WebSocketTransport.connect(progress, wsEndpoint, headersMap);
|
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'))
|
if (endpointURL.startsWith('ws'))
|
||||||
return endpointURL;
|
return endpointURL;
|
||||||
progress.log(`<ws preparing> retrieving websocket url from ${endpointURL}`);
|
progress.log(`<ws preparing> retrieving websocket url from ${endpointURL}`);
|
||||||
const httpURL = endpointURL.endsWith('/') ? `${endpointURL}json/version/` : `${endpointURL}/json/version/`;
|
const httpURL = endpointURL.endsWith('/') ? `${endpointURL}json/version/` : `${endpointURL}/json/version/`;
|
||||||
const json = await fetchData({
|
const json = await fetchData({
|
||||||
url: httpURL,
|
url: httpURL,
|
||||||
|
headers,
|
||||||
}, async (_, resp) => new Error(`Unexpected status ${resp.statusCode} when connecting to ${httpURL}.\n` +
|
}, 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://.`)
|
`This does not look like a DevTools server, try connecting via ws://.`)
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -256,9 +256,9 @@ test('should send extra headers with connect request', async ({ browserType, ser
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const [request] = await Promise.all([
|
const [request] = await Promise.all([
|
||||||
server.waitForWebSocketConnectionRequest(),
|
server.waitForRequest('/json/version/'),
|
||||||
browserType.connectOverCDP({
|
browserType.connectOverCDP({
|
||||||
endpointURL: `ws://localhost:${server.PORT}/ws`,
|
endpointURL: `http://localhost:${server.PORT}`,
|
||||||
headers: {
|
headers: {
|
||||||
'User-Agent': 'Playwright',
|
'User-Agent': 'Playwright',
|
||||||
'foo': 'bar',
|
'foo': 'bar',
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue