-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[feat]: add page.addInitScript()
#1335
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: e2505ce 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 SummaryAdded
Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Page
participant InitScripts
participant RegisterInit
participant CDP
User->>Page: addInitScript(script, arg)
Page->>InitScripts: normalizeInitScriptSource(script, arg, "page.addInitScript")
alt script is function
InitScripts->>InitScripts: Convert to IIFE with JSON.stringify(arg)
else script is string
InitScripts->>InitScripts: Return as-is
else script is {path}
InitScripts->>InitScripts: Read file & append sourceURL
else script is {content}
InitScripts->>InitScripts: Return content
end
InitScripts-->>Page: normalized source string
Page->>RegisterInit: registerInitScript(source)
RegisterInit->>RegisterInit: Check if already registered
RegisterInit->>RegisterInit: Add to initScripts array
RegisterInit->>CDP: installInitScriptOnSession(mainSession, source)
CDP->>CDP: Page.addScriptToEvaluateOnNewDocument
loop For each adopted OOPIF session
RegisterInit->>CDP: installInitScriptOnSession(session, source)
CDP->>CDP: Page.addScriptToEvaluateOnNewDocument
end
RegisterInit-->>Page: Complete
Page-->>User: Promise<void>
|
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.
6 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.
No issues found across 7 files
why
context.addInitScript(), which adds initialization scripts to all new pageswhat changed
page.addInitScript(), which just wraps & exposes logic that was already in place forcontext.addInitScript(), namelynormalizeInitScriptSources()andregisterInitScript()test plan
Summary by cubic
Adds page.addInitScript() to inject initialization scripts for a single page across navigations. Enables per-page scoping and function args, mirroring Playwright behavior.
Why:
What:
Test Plan:
Written for commit e2505ce. Summary will update automatically on new commits.