Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[fix]: makecontext.addInitScript() use correct isolated world#1308

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
seanmcguire12 wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromseanmcguire/stg-1012-make-contextaddinitscript-add-to-correct-js-world

Conversation

@seanmcguire12
Copy link
Member

why

  • currently, we add the init scripts to the main world
  • this is problematic, becausepage.evaluate() uses thev3-world
  • this means that you can't easily evaluate the script you add withaddInitScript()

what changed

  • makes sure that init scripts are added to thev3-world

test plan

  • added a test which callspage.evaluate() on a script added viacontext.addInitScript()

greptile-apps[bot] reacted with thumbs up emoji
@changeset-bot
Copy link

🦋 Changeset detected

Latest commit:6d78851

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
NameType
@browserbasehq/stagehandPatch
@browserbasehq/stagehand-evalsPatch

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-apps
Copy link
Contributor

Greptile Overview

Greptile Summary

Fixedcontext.addInitScript() to inject scripts into thev3-world isolated execution context instead of the main world, ensuring thatpage.evaluate() can access functions and globals added via init scripts.

Key changes:

  • ModifiedinstallInitScriptOnSession() inpackages/core/lib/v3/understudy/page.ts:135-138 to includeworldName: "v3-world" parameter
  • Added comprehensive test case verifying the fix works as expected
  • Change is consistent with how other v3 components (Frame,selectorResolver) use isolated worlds throughout the codebase

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The fix is a simple, targeted two-line change that correctly aligns init scripts with the isolated world pattern used throughout the v3 codebase. The change is well-tested with a new test case, follows existing patterns, and the implementation is correct
  • No files require special attention

Important Files Changed

File Analysis

FilenameScoreOverview
packages/core/lib/v3/understudy/page.ts5/5AddedworldName: "v3-world" toinstallInitScriptOnSession() to ensure init scripts execute in the same isolated world aspage.evaluate(), making injected globals accessible
packages/core/lib/v3/tests/context-addInitScript.spec.ts5/5Added test verifying that functions injected viacontext.addInitScript() are callable frompage.evaluate(), validating the isolated world fix
.changeset/seven-mice-draw.md5/5Changeset correctly describes the fix as a patch-level change with accurate user-facing description

Sequence Diagram

sequenceDiagram    participant User    participant Context    participant Page    participant CDPSession    participant Browser    participant IsolatedWorld as v3-world (Isolated)    User->>Context: addInitScript(fn)    Context->>Page: registerInitScript(source)    Page->>Page: Check if script already exists    Page->>Page: Add to initScripts array    Page->>CDPSession: Page.addScriptToEvaluateOnNewDocument    Note over CDPSession,Browser: worldName: "v3-world" (NEW)    CDPSession->>Browser: Install script in v3-world    Browser->>IsolatedWorld: Script registered for future docs        User->>Page: goto(url)    Browser->>IsolatedWorld: Execute init script in v3-world    Note over IsolatedWorld: window.sayHelloFromStagehand = ...        User->>Page: evaluate(fn)    Page->>Page: createIsolatedWorldForCurrentMain()    Note over Page,IsolatedWorld: Creates/reuses v3-world context    Page->>IsolatedWorld: Runtime.evaluate in v3-world    IsolatedWorld-->>Page: Access to init script globals    Page-->>User: Result
Loading

Copy link
Contributor

@greptile-appsgreptile-appsbot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

2 files reviewed, no comments

Edit Code Review Agent Settings |Greptile

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

1 more reviewer

@greptile-appsgreptile-apps[bot]greptile-apps[bot] left review comments

Reviewers whose approvals may not affect merge requirements

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@seanmcguire12

[8]ページ先頭

©2009-2025 Movatter.jp