-
Notifications
You must be signed in to change notification settings - Fork 16.3k
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
I am working on application's plugin/add-on system and I want to disallow from plugins/add-ons doing anything without user giving permissions to them. This can work great with isolated worlds, but isolated worlds still lack things. Node's vm
feels more powerful than Electron's isolated worlds, but Node's vm
doesn't work great with Electron.
You can't really set isolated world's window variables either without using hacks like executing JS in isolated world to set its window variables, which will make you struggle implementing functions properly.
Proposed Solution
The introduction of contextBridge.exposeInIsolatedWorld(worldId, apiKey, api)
. This would allow you to set isolated world's window properties and would be similar to contextBridge.exposeInMainWorld(apiKey, api)
.
Example:
webFrame.setIsolatedWorldInfo(1005, {
name: "Isolated World 5"
});
contextBridge.exposeInIsolatedWorld(1005, "api", {
doStuff() { console.log("Isolated World 5 is doing stuff"); }
});
await webFrame.executeJavaScriptInIsolatedWorld(1005, [
{
"code": "window.api.doStuff()"
}
]);
Console Output:
-> Isolated World 5 is doing stuff
Alternatives Considered
webFrame.setIsolatedWorldInfo
could allow setting window variables for that isolated world.
Additional Information
No response