web-frame-init.ts 1016 B

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