-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[v2]: rm internal page.evaluate usage #1386
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
Conversation
🦋 Changeset detectedLatest commit: d4a95f3 The changes in this PR will be included in the next version bump. 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 SummaryRefactors DOM helper script injection from per-page Key Changes:
Notes:
Confidence Score: 4/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Stagehand as Stagehand.init()
participant Context as StagehandContext.init()
participant Playwright as Playwright Context
participant Browser as Browser Window
Stagehand->>Context: StagehandContext.init(context, this)
Context->>Context: Check if context in WeakSet
alt Not in WeakSet
Context->>Playwright: context.addInitScript(stagehandInitScript)
Context->>Context: Add context to WeakSet
else Already in WeakSet
Context->>Context: Skip injection
end
Context-->>Stagehand: Return StagehandContext instance
Note over Stagehand,Browser: ⚠️ Duplicate injection occurs here
Stagehand->>Playwright: context.addInitScript(guardedScript)
Stagehand->>Browser: Create/navigate to page
Browser->>Browser: Execute init scripts
Browser->>Browser: Check window.__stagehandInjected
alt Not injected
Browser->>Browser: Set __stagehandInjected = true
Browser->>Browser: Execute shadow root interception
else Already injected
Browser->>Browser: Skip execution (guarded)
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.
10 files reviewed, 1 comment
| if (!StagehandContext.contextsWithInitScript.has(context)) { | ||
| await context.addInitScript({ content: stagehandInitScript }); | ||
| StagehandContext.contextsWithInitScript.add(context); |
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.
logic: duplicate init script injection - lib/index.ts:831 already calls context.addInitScript() with the same script content after StagehandContext.init() returns
| if (!StagehandContext.contextsWithInitScript.has(context)) { | |
| await context.addInitScript({ content: stagehandInitScript }); | |
| StagehandContext.contextsWithInitScript.add(context); | |
| // Note: init script is added in lib/index.ts after context creation | |
| // if (!StagehandContext.contextsWithInitScript.has(context)) { | |
| // await context.addInitScript({ content: stagehandInitScript }); | |
| // StagehandContext.contextsWithInitScript.add(context); | |
| // } |
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/StagehandContext.ts
Line: 94:96
Comment:
**logic:** duplicate init script injection - `lib/index.ts:831` already calls `context.addInitScript()` with the same script content after `StagehandContext.init()` returns
```suggestion
// Note: init script is added in lib/index.ts after context creation
// if (!StagehandContext.contextsWithInitScript.has(context)) {
// await context.addInitScript({ content: stagehandInitScript });
// StagehandContext.contextsWithInitScript.add(context);
// }
```
How can I resolve this? If you propose a fix, please make it concise.dafa667 to
7db3209
Compare
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.
No issues found across 9 files
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.
9 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 v2, this PR will be updated. # Releases ## @browserbasehq/[email protected] ### Patch Changes - [#1389](#1389) [`575226f`](575226f) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Retry DOM.getDocument on max depth exceeded with exponential backoff - [#1386](#1386) [`dbffb75`](dbffb75) Thanks [@seanmcguire12](https://github.com/seanmcguire12)! - Remove deprecated internal usage of page.evaluate ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`575226f`](575226f), [`dbffb75`](dbffb75)]: - @browserbasehq/[email protected] ## @browserbasehq/[email protected] ### Patch Changes - Updated dependencies \[[`575226f`](575226f), [`dbffb75`](dbffb75)]: - @browserbasehq/[email protected] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
why
what changed
test plan
Summary by cubic
Moves Stagehand DOM helper injection from per-page evaluate calls to a single Playwright context init script. Removes internal page.evaluate usage and drops unused scroll/XPath helpers on window.
Refactors
Migration
Written for commit d4a95f3. Summary will update automatically on new commits.