Skip to content

Comments

feat: contextBridge.executeInMainWorld#45229

Merged
samuelmaddock merged 1 commit intomainfrom
feat/bridge-execute
Jan 24, 2025
Merged

feat: contextBridge.executeInMainWorld#45229
samuelmaddock merged 1 commit intomainfrom
feat/bridge-execute

Conversation

@samuelmaddock
Copy link
Member

@samuelmaddock samuelmaddock commented Jan 16, 2025

Description of Change

Split from #44411
Implements part of RFC #8

contextBridge.executeInMainWorld is 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 executeInMainWorld are shared with exposeInMainWorld.

chrome.scripting.executeScript internals
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 as Experimental, we can update this in a follow up PR to prevent blocking this PR.

interface ExecutionScript {
  /**
   * A JavaScript function to evaluate. This function will be serialized which means
   * that any bound parameters and execution context will be lost.
   */
  func: (...args: any[]) => any;
  /**
   * The arguments to pass to the provided function. These arguments are proxied
   * across the context bridge.
   */
  args?: any[];
}

interface ContextBridge {
  executeInMainWorld(script: ExecutionScript): any;
}

Checklist

Release Notes

Notes: Added contextBridge.executeInMainWorld to safely execute code across world boundaries.

@electron-cation electron-cation bot added the new-pr 🌱 PR opened recently label Jan 16, 2025
@samuelmaddock samuelmaddock added semver/minor backwards-compatible functionality api-review/skip-delay ⏰ Skip the mandatory 7 day waiting period for new APIs target/35-x-y PR should also be added to the "35-x-y" branch. labels Jan 16, 2025
Copy link
Member

@erickzhao erickzhao left a comment

Choose a reason for hiding this comment

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

API LGTM

Copy link
Member

@itsananderson itsananderson left a comment

Choose a reason for hiding this comment

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

API LGTM

Copy link
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

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

API LGTM

@codebytere codebytere added api-review/skip-delay ⏰ Skip the mandatory 7 day waiting period for new APIs and removed api-review/skip-delay ⏰ Skip the mandatory 7 day waiting period for new APIs labels Jan 22, 2025
@samuelmaddock samuelmaddock merged commit 9964771 into main Jan 24, 2025
74 checks passed
@release-clerk
Copy link

release-clerk bot commented Jan 24, 2025

Release Notes Persisted

Added contextBridge.executeInMainWorld to safely execute code across world boundaries.

@samuelmaddock samuelmaddock deleted the feat/bridge-execute branch January 24, 2025 02:12
@trop
Copy link
Contributor

trop bot commented Jan 24, 2025

I have automatically backported this PR to "35-x-y", please check out #45330

@trop trop bot added in-flight/35-x-y and removed target/35-x-y PR should also be added to the "35-x-y" branch. labels Jan 24, 2025
@trop trop bot added merged/35-x-y PR was merged to the "35-x-y" branch. and removed in-flight/35-x-y labels Jan 31, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-review/approved ✅ api-review/skip-delay ⏰ Skip the mandatory 7 day waiting period for new APIs merged/35-x-y PR was merged to the "35-x-y" branch. semver/minor backwards-compatible functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants