mirror of
https://github.com/microsoft/playwright.git
synced 2024-12-15 06:02:57 +03:00
b29b7df47e
There are a few ways for `connect()` to finish: - `Browser.close()` from the client side. - Browser on the server side did exit (e.g. crashed). - Connection was dropped by either of the sides. We reduce all the cases to the last one by dropping the connection when client wants calls `Browser.close()` or server-side browser exits. In all these cases we should properly cleanup on the server side, and ensure that all promises reject on the client side.
39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
const cluster = require('cluster');
|
|
|
|
async function start() {
|
|
const { playwrightPath, browserTypeName, launchOptions, stallOnClose, disconnectOnSIGHUP } = JSON.parse(process.argv[2]);
|
|
if (stallOnClose) {
|
|
launchOptions.__testHookGracefullyClose = () => {
|
|
console.log(`(stalled=>true)`);
|
|
return new Promise(() => {});
|
|
};
|
|
}
|
|
|
|
const playwright = require(require('path').join(playwrightPath, 'index'));
|
|
|
|
if (disconnectOnSIGHUP)
|
|
launchOptions.handleSIGHUP = false;
|
|
const browserServer = await playwright[browserTypeName].launchServer(launchOptions);
|
|
if (disconnectOnSIGHUP)
|
|
process.on('SIGHUP', () => browserServer._disconnectForTest());
|
|
|
|
browserServer.on('close', (exitCode, signal) => {
|
|
console.log(`(exitCode=>${exitCode})`);
|
|
console.log(`(signal=>${signal})`);
|
|
});
|
|
console.log(`(pid=>${browserServer.process().pid})`);
|
|
console.log(`(wsEndpoint=>${browserServer.wsEndpoint()})`);
|
|
}
|
|
|
|
process.on('uncaughtException', error => console.log(error));
|
|
process.on('unhandledRejection', reason => console.log(reason));
|
|
|
|
if (cluster.isWorker || !JSON.parse(process.argv[2]).inCluster) {
|
|
start();
|
|
} else {
|
|
cluster.fork();
|
|
cluster.on('exit', (worker, code, signal) => {
|
|
process.exit(0);
|
|
});
|
|
}
|