web-frame-init.ts 952 B

12345678910111213141516171819202122232425
  1. import { webFrame, WebFrame } from 'electron';
  2. import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
  3. // All keys of WebFrame that extend Function
  4. type WebFrameMethod = {
  5. [K in keyof WebFrame]:
  6. WebFrame[K] extends Function ? K : never
  7. }
  8. export const webFrameInit = () => {
  9. // Call webFrame method
  10. ipcRendererUtils.handle('ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', (
  11. event, method: keyof WebFrameMethod, ...args: any[]
  12. ) => {
  13. // TODO(MarshallOfSound): Remove once the world-safe-execute-javascript deprecation warning is removed
  14. if (method.startsWith('executeJavaScript')) {
  15. return (webFrame as any)[`_${method}`](...args);
  16. }
  17. // The TypeScript compiler cannot handle the sheer number of
  18. // call signatures here and simply gives up. Incorrect invocations
  19. // will be caught by "keyof WebFrameMethod" though.
  20. return (webFrame[method] as any)(...args);
  21. });
  22. };