Files
zn-ai/packages/electron-chrome-extensions/spec/fixtures/crx-test-preload.ts
2025-11-15 22:41:50 +08:00

24 lines
642 B
TypeScript

import { contextBridge, ipcRenderer } from 'electron'
import { injectBrowserAction } from '../../src/browser-action'
// This should go without saying, but you should never do this in a production
// app. These bindings are purely for testing convenience.
const apiName = 'electronTest'
const api = {
sendIpc(channel: string, ...args: any[]) {
return ipcRenderer.send(channel, ...args)
},
invokeIpc(channel: string, ...args: any[]) {
return ipcRenderer.invoke(channel, ...args)
},
}
try {
contextBridge.exposeInMainWorld(apiName, api)
} catch {
window[apiName] = api
}
// Inject in all test pages.
injectBrowserAction()