chore(extension): exit gracefully when waiting for extension connection (#754)
This commit is contained in:
@@ -57,7 +57,7 @@ program
|
||||
.addOption(new Option('--extension', 'Connect to a running browser instance (Edge/Chrome only). Requires the "Playwright MCP Bridge" browser extension to be installed.').hideHelp())
|
||||
.addOption(new Option('--vision', 'Legacy option, use --caps=vision instead').hideHelp())
|
||||
.action(async options => {
|
||||
setupExitWatchdog();
|
||||
const abortController = setupExitWatchdog();
|
||||
|
||||
if (options.vision) {
|
||||
// eslint-disable-next-line no-console
|
||||
@@ -67,7 +67,7 @@ program
|
||||
const config = await resolveCLIConfig(options);
|
||||
|
||||
if (options.extension) {
|
||||
await runWithExtension(config);
|
||||
await runWithExtension(config, abortController);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -85,12 +85,15 @@ program
|
||||
});
|
||||
|
||||
function setupExitWatchdog() {
|
||||
const abortController = new AbortController();
|
||||
|
||||
let isExiting = false;
|
||||
const handleExit = async () => {
|
||||
if (isExiting)
|
||||
return;
|
||||
isExiting = true;
|
||||
setTimeout(() => process.exit(0), 15000);
|
||||
abortController.abort('Process exiting');
|
||||
await Context.disposeAll();
|
||||
process.exit(0);
|
||||
};
|
||||
@@ -98,6 +101,8 @@ function setupExitWatchdog() {
|
||||
process.stdin.on('close', handleExit);
|
||||
process.on('SIGINT', handleExit);
|
||||
process.on('SIGTERM', handleExit);
|
||||
|
||||
return abortController;
|
||||
}
|
||||
|
||||
void program.parseAsync(process.argv);
|
||||
|
||||
Reference in New Issue
Block a user