Right after a navigation commits there is a window in which the new
document has no document element yet, so observe(document.documentElement)
is observe(null) and throws
TypeError: Failed to execute 'observe' on 'MutationObserver':
parameter 1 is not of type 'Node'
Called on the heels of a click that navigates, that exception fails the
whole settle wait: the click has already gone through, but the caller
sees an error and never learns where the tab landed.
A Document is always a Node, and subtree: true from it covers everything
documentElement would have — including a document element that appears,
or is replaced, later.
The regression test removes the document element outright, standing in
for that post-commit window; it fails with the exact production error
before this change.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The bug
waitForDomIdleinstalls itsMutationObserverondocument.documentElement. Right after a navigation commits there is a window in which the new document does not have a document element yet, so that argument isnulland the page throws:Because
waitForDomIdleis one leg ofwaitUntilLoaded, this surfaces on the path where it hurts most — a click that navigates. Found in Umwelt, submitting a Google search form: the click went through and the browser landed on the results page, but the caller got an exception instead of aNavigation, and its recorded location stayed on the page the tab had already left.The fix
Observe
documentinstead. ADocumentis always aNode, andsubtree: truefrom it covers everythingdocumentElementwould have, including a document element that appears — or is replaced — later. Strictly wider coverage, no null to guard.Test
waitForDomIdle should report idle on a document with no document elementremoves the document element outright, standing in for that post-commit window (the real timing is a race and would make a flaky test; the precondition it produces is identical).Verified it is a real regression test — with the old line restored it fails with the exact production error:
Full
WaitUntilLoadedTestsuite green onjvmTestwith the fix in place.🤖 Generated with Claude Code