Skip to content

[Feature Request]: contextBridge.exposeInIsolatedWorld #32588

@IdkGoodName

Description

@IdkGoodName

Preflight Checklist

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions