Skip to content

Chrome DevTools for coding agents

fix: disable Puppeteer signal handlers for launched browsers (#3238)

Alex Rudenko3afec73bd39f
diff --git a/src/BrowserManager.ts b/src/BrowserManager.ts
index b34666bb..54ed3962 100644
--- a/src/BrowserManager.ts
+++ b/src/BrowserManager.ts
@@ -284,6 +284,12 @@ export class BrowserManager {
blocklist,
allowlist,
logger: puppeteerLogger,
+ // The entry points own signal handling and call close(), which
+ // closes the browser gracefully. Puppeteer's handlers would SIGKILL
+ // Chrome synchronously on the same signal and win the race.
+ handleSIGINT: false,
+ handleSIGTERM: false,
+ handleSIGHUP: false,
});
if (this.#options.logFile) {
// FIXME: we are probably subscribing too late to catch startup logs. We
diff --git a/tests/browser.test.ts b/tests/browser.test.ts
index f8d482bd..a48993ef 100644
--- a/tests/browser.test.ts
+++ b/tests/browser.test.ts
@@ -151,6 +151,22 @@ describe('browser', () => {
});
});
+ it('disables Puppeteer signal handlers so close() can shut the browser down gracefully', async () => {
+ const pptrBrowser = createMockPuppeteerBrowser();
+ const launchStub = sinon.stub(puppeteer, 'launch').resolves(pptrBrowser);
+ const manager = new BrowserManager(
+ createMockParsedArguments({isolated: true}),
+ );
+
+ await manager.ensureBrowser();
+
+ sinon.assert.calledOnceWithMatch(launchStub, {
+ handleSIGINT: false,
+ handleSIGTERM: false,
+ handleSIGHUP: false,
+ });
+ });
+
it('connects to a browser when browserUrl is set and disconnects on close()', async () => {
const pptrBrowser = createMockPuppeteerBrowser();
const launchStub = sinon.stub(puppeteer, 'launch');