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
feat: expose executeJavaScriptInIsolatedWorld on webContents #21190
Conversation
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.
Looks good to me since the API is already in webFrame
.
docs/api/web-contents.md
Outdated
@@ -1031,6 +1031,17 @@ contents.executeJavaScript('fetch("https://jsonplaceholder.typicode.com/users/1" | |||
}) | |||
``` | |||
|
|||
#### `contents.executeJavaScriptInIsolatedWorld(worldId, scripts[, userGesture])` | |||
|
|||
* `worldId` Integer - The ID of the world to run the javascript in, `0` is the default world, `999` is the world used by Electrons `contextIsolation` feature. You can provide any integer here. |
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.
For my own learning: do we have any docs that guide when you'd want to use a world with an ID between 1-998?
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.
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.
Would probably be a little less confusing for consumers to use constants provided by Electron, I would think?
Co-Authored-By: loc <andy@slack-corp.com>
Approved for backport to 8-x-y by the releases WG. |
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.
I would like to see a helper wrapping the duplicated ipcMainUtils.invokeInWebContents(this, false, 'ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, ...args)
, which we now have 3 times in the code. Otherwise looks good!
Release Notes Persisted
|
I have automatically backported this PR to "8-x-y", please check out #21267 |
This exposes
executeJavaScriptInIsolatedWorld
in a similar way toexecuteJavaScript
so that folks can call it from the main process. Also cleans up the code we use for the main-process sideexecuteJavaScript
Notes: Exposed
executeJavaScriptInIsolatedWorld
on thewebContents
API