Scope ModelContext to Document, and handle detached documents#177
Merged
Conversation
domfarolino
commented
May 15, 2026
ModelContext lifetime to Document and handle detached documents
ModelContext lifetime to Document and handle detached documentsModelContext to Document, and handle detached documents
bwalderman
requested changes
May 18, 2026
bwalderman
approved these changes
May 18, 2026
github-actions Bot
added a commit
that referenced
this pull request
May 19, 2026
SHA: 986f461 Reason: push, by domfarolino Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.
This PR does two things:
ModelContextobject toDocumentinstead ofNavigator, and explains why.modelContextattribute return null when the document is detached (by checking when the Window's browsing context is null). This matches the behavior of thecontentWindowandcontentDocumentgetters—return nothing, even if those objects are allocated and kept alive by other references, in the detached document case.Note that this PR does not handle the "document not fully active" case, which covers detached documents and documents in the bf-cache. Non-fully active documents probably shouldn't impact the
modelContextgetter—it seems weird for getters like that to return different values based on whether the document is in the bf-cache—but rather need special behavior in theregisterTool()method, and the cominggetTools()andexecuteTool()methods.This PR mostly addresses #173, with the exception of considering moving the API to
self, fromnavigator. As much as I want to do this, I'm sympathetic to w3ctag/design-principles#426 (comment), so for now I'm leaning towards not moving it. So I'll say that this PR closes #173.Preview | Diff