in src/extension-runners/chromium.js [380:420]
async exit() {
this.exiting = true;
// Wait for the setup to complete if the extension runner is already
// being started.
if (this._promiseSetupDone) {
// Ignore initialization errors if any.
await this._promiseSetupDone.catch((err) => {
log.debug(`ignored setup error on chromium runner shutdown: ${err}`);
});
}
if (this.chromiumInstance) {
await this.chromiumInstance.kill();
this.chromiumInstance = null;
}
if (this.wss) {
// Close all websocket clients, closing the WebSocketServer
// does not terminate the existing connection and it wouldn't
// resolve until all of the existing connections are closed.
for (const wssClient of this.wss?.clients || []) {
if (wssClient.readyState === WebSocket.OPEN) {
wssClient.terminate();
}
}
await new Promise((resolve) =>
this.wss ? this.wss.close(resolve) : resolve(),
);
this.wss = null;
}
// Call all the registered cleanup callbacks.
for (const fn of this.cleanupCallbacks) {
try {
fn();
} catch (error) {
log.error(error);
}
}
}