MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Feature]: Control script injection for individual frames
@Lakshmisha-KS is already working on this.
Since Feb 12, 2025.
- Dominant language
- PowerShell
- Stars
- 526
- Forks
- 67
- PR merge metrics
- No merged PRs in 30d
Description
Describe the feature/enhancement you need
I'd like to be able to inject different scripts into individual frames. An AddScriptToExecuteOnDocumentCreatedAsync method for CoreWebView2Frame might be sufficient. I'm using WebView2 in a .NET WPF app via the Microsoft.Web.WebView2 package.
The scenario/use case where you would use this feature
I'm injecting scripts that contain a subscriber ID and access token for the page, as well as JS code that uses this information for connecting to a backend service. However, I want the scripts to be different for each iframe because I want to treat them as unique subscribers. Some scripts I want to inject to the top level frame only, to avoid information leakage in case that top level frame loads some external page. The behavior and API for injecting scripts should be the same for windows created with window.open() and iframes.
How important is this request to you?
Impactful. My app's user experience would be significantly compromised without it.
Suggested implementation
No response
What does your app do? Is there a pending deadline for this request?
I'm currently experimenting with various WV2 methods and events, my working theory is this:
- Remove all injected scripts in
FrameCreatedevent handler - Cancel navigation in
FrameNavigationStartingevent handler, and start a sequence when I inject scripts and then navigate the frame - unfortunately there's no reference to the frame in the event args, so this is probably a dead end.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.