-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[feat]: add context.addInitScript()
#1300
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat]: add context.addInitScript()
#1300
Conversation
🦋 Changeset detectedLatest commit: b45d574 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Greptile OverviewGreptile SummaryThis PR adds Major changes:
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant V3Context
participant Page
participant CDPSession
participant Browser
User->>V3Context: addInitScript(script, arg?)
V3Context->>V3Context: normalizeInitScriptSource(script, arg)
V3Context->>V3Context: store script in initScripts[]
V3Context->>V3Context: pages()
loop For each existing page
V3Context->>Page: registerInitScript(source)
Page->>Page: check if script already registered
Page->>Page: add to initScripts[]
Page->>CDPSession: Page.addScriptToEvaluateOnNewDocument
loop For all sessions (main + OOPIFs)
CDPSession->>Browser: Register init script
end
end
Note over User,Browser: When new page is created
User->>V3Context: newPage()
V3Context->>Browser: Target.createTarget
Browser->>V3Context: attachedToTarget event
V3Context->>Page: create Page instance
V3Context->>V3Context: applyInitScriptsToPage(page)
loop For each stored script
V3Context->>Page: registerInitScript(source)
Page->>CDPSession: Page.addScriptToEvaluateOnNewDocument
CDPSession->>Browser: Register init script
end
Note over User,Browser: When OOPIF is attached
Browser->>Page: adoptOopifSession(childSession)
Page->>Page: applyInitScriptsToSession(childSession)
loop For each stored script
Page->>CDPSession: Page.addScriptToEvaluateOnNewDocument
CDPSession->>Browser: Register init script for OOPIF
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, no comments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, no comments
This PR was opened by the [Changesets release](https://github.com/changesets/action) GitHub action. When you're ready to do a release, you can merge this and the packages will be published to npm automatically. If you're not ready to do a release yet, that's fine, whenever you add more changesets to main, this PR will be updated. # Releases ## @browserbasehq/stagehand@3.0.4 ### Patch Changes - [#1281](#1281) [`fa18cfd`](fa18cfd) Thanks [@monadoid](https://github.com/monadoid)! - Add Browserbase session URL and debug URL accessors - [#1264](#1264) [`767d168`](767d168) Thanks [@Kylejeong2](https://github.com/Kylejeong2)! - feat: adding gpt 5.1 to stagehand - [#1282](#1282) [`f27a99c`](f27a99c) Thanks [@tkattkat](https://github.com/tkattkat)! - Add support for zod 4, while maintaining backwards compatibility for zod 3 - [#1295](#1295) [`91a1ca0`](91a1ca0) Thanks [@tkattkat](https://github.com/tkattkat)! - Patch zod handling of non objects in extract - [#1298](#1298) [`1dd7d43`](1dd7d43) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - log Browserbase session status when websocket is closed due to session timeout - [#1284](#1284) [`c0f3b98`](c0f3b98) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - fix: waitForDomNetworkQuiet() causing `act()` to hang indefinitely - [#1246](#1246) [`44bb4f5`](44bb4f5) Thanks [@filip-michalsky](https://github.com/filip-michalsky)! - make ci faster - [#1300](#1300) [`2b70347`](2b70347) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - add support for context.addInitScript() ## @browserbasehq/stagehand-evals@1.1.4 ### Patch Changes - Updated dependencies \[[`fa18cfd`](fa18cfd), [`767d168`](767d168), [`f27a99c`](f27a99c), [`91a1ca0`](91a1ca0), [`1dd7d43`](1dd7d43), [`c0f3b98`](c0f3b98), [`44bb4f5`](44bb4f5), [`2b70347`](2b70347)]: - @browserbasehq/stagehand@3.0.4 Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
what changed
context.addInitScripts()which callsPage.addScriptToEvaluateOnNewDocumentwhenever we attach to a page targettest plan