Commit 3f7e082
fix(hackbrowser): guard request.allHeaders() so a closed target can't crash the worker (#104)
The page.on("request", async …) capture handler awaited request.allHeaders() without a
try/catch. In headed mode a page/context/browser can close mid-crawl (a popup/tab closing,
a navigation) while requests are still in flight; allHeaders() then rejects with "Target
page, context or browser has been closed". Because the handler is a fire-and-forget async
listener and the worker installs no unhandledRejection guard, that rejection takes down the
whole worker process (exit 1) — the crawl ends after only a fraction of the target.
Verified from code + repro: allHeaders() is the SOLE unguarded await in the handler (the UI
-context and response branches below are already try/caught); Bun terminates the process on
an unhandled rejection; the worker has no safety net. Wrap the call and drop the capture on
a closed target instead (a request whose headers never arrived isn't a usable capture), with
a debug line naming the in-flight URL for diagnosis. Repro confirms no unhandled rejection
after the fix; 99/99 tests pass.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 2b05236 commit 3f7e082
1 file changed
Lines changed: 9 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
479 | | - | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
480 | 488 | | |
481 | 489 | | |
482 | 490 | | |
| |||
0 commit comments