Repository navigation
Don't hold opening a Firefox tab on its window taking focus - #33
Merged
Merged
Conversation
Firefox answers browsingContext.activate only once its window has taken focus as well as selected the tab, and waits for that without a limit. A window still starting up headless may never fire the events it waits for, so opening the first page in a freshly launched Firefox could hang: the page loaded, but open() never resolved. CI caught it on main after #32 merged, in driven.firefox's first test. Bringing a tab to the front now waits two seconds at most for that answer, then goes on (the tab is in front by then); a refusal that comes sooner still fails it. A unit test drives a stand-in Firefox that never answers. The integration test's waits now give up before the test's own timeout, saying what the tabs showed, and its first test, a cold launch, has room for the 30 seconds the app gives Firefox to open its port.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
CI on
mainfailed after #32 merged:driven.firefox's first test ("launches it with a profile of its own…") ran into its 30 s timeout. The later tests in that file passed, including the captures, which bring the tab to the front again.Opening a page in a driven Firefox navigates the tab, then brings it to the front with
browsingContext.activate. Firefox (remote/…/root/browsingContext.sys.mjsandWindowManager.focusWindow) selects the tab at once. It answers only once its window has fired bothactivateandfocus, and it waits for them with no limit. A window still starting up headless may never fire them, soopen()could hang on a freshly launched Firefox even though the page itself loaded. Once the window is active, later activations answer at once, which matches the rest of the file passing.DrivenFirefox.activatenow waits at mostACTIVATE_WAIT_MS(2 s) for that answer, then goes on. The tab is already selected by then. A refusal that comes sooner, such as a closed tab, still fails it; an answer that comes later is ignored.driven.firefox.test.ts:I couldn't make the hang happen here: about 30 fresh launches of Firefox 157, 25 of them under CPU load, all answered
activatewithin about 20 ms. So the cause above comes from reading Firefox's source and from the CI run, not from a reproduction. If it stalls again, the new wait errors will say what the tab showed.How it was tested
test/unit/bidi.test.ts): a stand-in Firefox that never answersactivate.open()resolves once the wait is up; without the fix it times out. A second test checks that a refusal still comes through, and that an unknown tab is still refused as closed.driven.firefox.test.tspassed 4 runs in a row, anddriven-firefox.e2eandbrowsers.e2epassed in the built app.Checklist
feature/…,bugfix/…) intomain, and does one thingnpm run typecheck,npm run lint:fsd,npm run lint:structure,npm run lint,npm run lint:unused,npm run lint:duplicates,npm run lint:secrets,npm testandnpm run test:e2epass (1325 unit and integration tests, 139 end-to-end)docs/SPEC.mddescribes any behaviour this changes: none. A tab is still brought to the front; only the wait for Firefox's answer is bounded.[Unreleased]inCHANGELOG.md: none. Opening pages in Firefox hasn't been released yet.Generated by Claude Code