[docs]: add docs for setDomainPolicy#2289
Merged
seanmcguire12 merged 2 commits intoJul 13, 2026
Merged
Conversation
|
Contributor
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Workflows to automatically generate PRs for you. |
seanmcguire12
force-pushed
the
seanmcguire/stg-2426-add-docs-for-domain-policy
branch
from
July 13, 2026 17:33
4468c7c to
644f32e
Compare
seanmcguire12
marked this pull request as ready for review
July 13, 2026 18:09
Contributor
There was a problem hiding this comment.
No issues found across 1 file
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Architecture diagram
sequenceDiagram
participant UserCode as User Script
participant Context as V3Context
participant Network as Network Domain Manager
participant CDP as Chrome DevTools Protocol
participant CDPSession as CDP Session(s)
Note over UserCode,CDPSession: Domain Policy Flow
UserCode->>Context: setDomainPolicy(policy)
Context->>Context: Validate policy (DomainPolicy | null)
alt Invalid policy (e.g. URL with path)
Context-->>UserCode: StagehandInvalidArgumentError
else Valid policy
Context->>Network: Apply domain policy (allowedDomains + blockedDomains)
Network->>Network: Normalize patterns (lowercase, deduplicate)
Network->>CDPSession: Configure network blocking (one or more sessions)
alt All sessions updated successfully
CDPSession-->>Network: OK
Network-->>Context: Success
Context-->>UserCode: Resolved
else Some sessions fail
CDPSession-->>Network: Error
Network-->>Context: Partial failure
Context-->>UserCode: StagehandSetDomainPolicyError (with failures[])
end
end
Note over UserCode,CDPSession: Runtime Request Flow
UserCode->>Context: page.goto("https://example.com")
Context->>CDP: Navigate request
CDP->>Network: Check policy for "example.com"
alt Domain allowed (no matching blockedDomains, matches allowedDomains)
Network-->>CDP: Allow
CDP-->>Context: Page loaded
Context-->>UserCode: Page object
else Domain blocked (matches blockedDomains or rejects allowedDomains)
Network-->>CDP: BlockedByClient
CDP-->>Context: Request blocked
Context-->>UserCode: Error (BlockedByClient)
end
Note over UserCode,CDPSession: New Target (popup/window.open)
UserCode->>Context: action opens popup
Context->>Network: Check policy for new target domain
alt Domain allowed
Context->>CDPSession: Attach to new target
CDPSession-->>Context: Target active
Context-->>UserCode: Page object
else Domain blocked (race-sensitive)
Context->>CDPSession: Close target (fallback)
CDPSession-->>Context: Target closed
Context-->>UserCode: Error
end
Note over UserCode,CDPSession: Subresource Checks
UserCode->>Context: iframe.src="https://ads.example.com"
Context->>CDP: Load iframe content
CDP->>Network: Check policy for "ads.example.com"
alt Domain blocked (overrides allowedDomains)
Network-->>CDP: BlockedByClient
CDP-->>Context: Subresource blocked
else Domain allowed
Network-->>CDP: Allow
CDP-->>Context: Content loaded
end
Note over UserCode,CDPSession: Policy Read
UserCode->>Context: getDomainPolicy()
Context->>Context: Return stored DomainPolicy | null
Context-->>UserCode: DomainPolicy object
Note over UserCode,CDPSession: Clear Policy
UserCode->>Context: setDomainPolicy(null)
Context->>Network: Remove domain policy
Network->>CDPSession: Disable network blocking
CDPSession-->>Network: OK
Network-->>Context: Policy cleared
Context-->>UserCode: Resolved
miguelg719
approved these changes
Jul 13, 2026
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.
why
setDomainPolicy()what changed
Summary by cubic
Adds docs for
context.setDomainPolicy()andcontext.getDomainPolicy()to control HTTP(S) requests by domain across a context, with examples and error details. Addresses Linear STG-2426.setDomainPolicy(policy: DomainPolicy | null)andgetDomainPolicy()with TypeScript signatures, behavior, scope (pages, iframes, subresources), and how to clear.*.example.comdoesn’t matchexample.com), case-insensitive matching, duplicate patterns ignored, and no schemes/paths/ports;blockedDomainsoverridesallowedDomains; non-HTTP(S) unaffected; blocked requests show Chrome “BlockedByClient”.@browserbasehq/stagehand, and updated API reference with new errors (StagehandInvalidArgumentError,StagehandSetDomainPolicyError) plusV3ContextandDomainPolicyinterface snippets.Written for commit 644f32e. Summary will update on new commits.