mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
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 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://.`)
|
||||
);
|
||||
|
||||
@ -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',
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user