feat: contextBridge.executeInMainWorld#45229
Merged
samuelmaddock merged 1 commit intomainfrom Jan 24, 2025
Merged
Conversation
23 tasks
|
Release Notes Persisted
|
Contributor
|
I have automatically backported this PR to "35-x-y", please check out #45330 |
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Split from #44411
Implements part of RFC #8
contextBridge.executeInMainWorldis added to accept{ func: Function, args: any[] }. This allows serializing a function and arguments over the context bridge to be executed in the main world.Tests to guarantee return values go through the context bridge reuse the logic from our webFrame.executeJavaScript world safe test. The internals of
executeInMainWorldare shared withexposeInMainWorld.chrome.scripting.executeScript internals
[serializableFunction]for Function argumenthttps://source.chromium.org/chromium/chromium/src/+/main:chrome/common/extensions/api/scripting.idl;l=47-53;drc=f54f71679bfe9b9ef10c785369112fb2d0661750
ArgumentSpec::ParseArgumentToFunctionserializes the function usingv8::Function::FunctionProtoToStringhttps://source.chromium.org/chromium/chromium/src/+/main:extensions/renderer/bindings/argument_spec.cc;l=744-764;drc=38412897b24a44461ec89d2167e2110a3793c98c
ScriptingExecuteScriptFunction::Runconstructs the function string and serializes arguments as JSONhttps://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/extensions/api/scripting/scripting_api.cc;l=617-641;drc=01ab59ae08a38a361da7dac41e36f387f6600ed5
contextBridge.executeInMainWorld(script) types
The types are currently using
any. We'll need to modify our type definition generator to better support adding generics here. Given the API being marked asExperimental, we can update this in a follow up PR to prevent blocking this PR.Checklist
npm testpassesRelease Notes
Notes: Added
contextBridge.executeInMainWorldto safely execute code across world boundaries.