MicrosoftEdge / MicrosoftEdge/WebView2Feedback
[Feature]: [Extensions] Code injection before any Extension code runs
@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
To achieve some functionality, we had to change the behaviour of some Chrome Extension APIs, for example chrome.tabs.query . This was achieved by injecting JS shims into the extension code which replaced the API behaviour.
There are currently two ways we found to inject JS into extensions:
- runtime: attaching chrome devtools session to the extension, then calling "
Runtime.evaluate" to execute JS in the context of the extension. This then replaces the real API (e.g.chrome.tabs.query) with the modified one. - at rest: modify the extension file itself. While doable, this can cause licensing issues with software that can't have its sources modified.
The "runtime" approach would be ideal, however there is currently a timing issue - there is no way to guarantee execution of the injected shim code before extension code starts executing. For websites, we could use a workaround by using chromium devtools to ensure they websites start in a "wait for debugger" mode, but we have not yet discovered a way how to load extension in the same manner.
Ideally, an API similar to AddScriptToExecuteOnDocumentCreatedAsync would be provided for extensions as well.
The scenario/use case where you would use this feature
As we're building a browser with intention to host extensions, some amount of app-to-extension communication needs to happen as we need to re-implement some of the chrome extension APIs, e.g. chrome.tabs.query
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?
No response
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.