admin管理员组文章数量:1123377
I have created my Electron App with
create-electron-app $projDir --template=vite-typescript
In my BrowserWindow's webpreferences I have set
contextIsolation: true
nodeIntegration: false
I have defined the API which i want to use in my Renderer context inside preload.ts like this:
const WORLD_ID: number = 1004;
const API_KEY: string = "api";
interface IApi {
myFun: <T>(...args: any) => Promise<T>;
}
const api: IApi = {
myFun: <T>(...args: any) => ipcRenderer.invoke("my-event", ...args) as Promise<T>
}
contextBridge.exposeInIsolatedWorld(
WORLD_ID, API_KEY, api
);
export { type IApi, API_KEY, WORLD_ID };
i have defined a interface.d.ts for the api:
import { type IApi, API_KEY } from '@/preload';
declare global {
interface Window {
[API_KEY]: IApi
}
}
The documentation () suggests I can now use the api like this:
// Renderer (In isolated world id1004)
window.api.myFun()
- I wasn't able to find any example on how to run the Renderer in an isolated world (as so kindly remarked in the docs). Can you help?
webFrame.executeInIsolatedWorld()
does not work since webFrame requires the path module, which is not available in the renderer. Is there an alternative?
本文标签: typescriptUse isolated world API in electron rendererStack Overflow
版权声明:本文标题:typescript - Use isolated world API in electron renderer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736566295a1944708.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论