Skip to content

Commit

Permalink
fix: ignore cert errors in the test driver (#1161)
Browse files Browse the repository at this point in the history
Closes #1162
  • Loading branch information
OrKoN authored Aug 10, 2023
1 parent 9f9a645 commit d0de039
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 36 deletions.
47 changes: 32 additions & 15 deletions src/bidiServer/bidiServerRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ export class BidiServerRunner {
run(
bidiPort: number,
onNewBidiConnectionOpen: (
bidiServer: ITransport
bidiServer: ITransport,
args?: string[]
) => Promise<() => void> | (() => void)
) {
let jsonBody: any;
const server = http.createServer(
async (request: http.IncomingMessage, response: http.ServerResponse) => {
debugInternal(
Expand All @@ -67,20 +69,30 @@ export class BidiServerRunner {

// https://w3c.github.io/webdriver-bidi/#transport, step 2.
if (request.url === '/session') {
response.writeHead(200, {
'Content-Type': 'application/json;charset=utf-8',
'Cache-Control': 'no-cache',
});
response.write(
JSON.stringify({
value: {
sessionId: '1',
capabilities: {
webSocketUrl: `ws://localhost:${bidiPort}`,
},
},
const body: Uint8Array[] = [];
request
.on('data', (chunk) => {
body.push(chunk);
})
);
.on('end', () => {
jsonBody = JSON.parse(Buffer.concat(body).toString());
response.writeHead(200, {
'Content-Type': 'application/json;charset=utf-8',
'Cache-Control': 'no-cache',
});
response.write(
JSON.stringify({
value: {
sessionId: '1',
capabilities: {
webSocketUrl: `ws://localhost:${bidiPort}`,
},
},
})
);
return response.end();
});
return;
} else if (request.url.startsWith('/session')) {
debugInternal(
`Unknown session command ${
Expand Down Expand Up @@ -126,11 +138,16 @@ export class BidiServerRunner {
});

wsServer.on('request', async (request: websocket.request) => {
const chromeOptions =
jsonBody?.capabilities?.alwaysMatch?.['goog:chromeOptions'];
debugInternal('new WS request received:', request.resourceURL.path);

const bidiServer = new BidiServer();

const onBidiConnectionClosed = await onNewBidiConnectionOpen(bidiServer);
const onBidiConnectionClosed = await onNewBidiConnectionOpen(
bidiServer,
chromeOptions?.args
);

const connection = request.accept();

Expand Down
16 changes: 13 additions & 3 deletions src/bidiServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,14 @@ function parseArguments(): {

debugInfo('Launching BiDi server...');

new BidiServerRunner().run(port, (bidiServer) => {
return onNewBidiConnectionOpen(channel, headless, bidiServer, verbose);
new BidiServerRunner().run(port, (bidiServer, chromeArgs) => {
return onNewBidiConnectionOpen(
channel,
headless,
bidiServer,
verbose,
chromeArgs
);
});
debugInfo('BiDi server launched');
} catch (e) {
Expand All @@ -104,7 +110,8 @@ async function onNewBidiConnectionOpen(
channel: ChromeReleaseChannel,
headless: boolean,
bidiTransport: ITransport,
verbose: boolean
verbose: boolean,
chromeArgs?: string[]
) {
// 1. Launch the browser using @puppeteer/browsers.
const profileDir = await mkdtemp(
Expand All @@ -127,6 +134,9 @@ async function onNewBidiConnectionOpen(
'--use-mock-keychain',
`--user-data-dir=${profileDir}`,
// keep-sorted end
...(chromeArgs
? chromeArgs.filter((arg) => !arg.startsWith('--headless'))
: []),
'about:blank',
];

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit d0de039

Please sign in to comment.