Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export preload function #62

Open
brumik opened this issue Dec 19, 2021 · 2 comments
Open

Export preload function #62

brumik opened this issue Dec 19, 2021 · 2 comments

Comments

@brumik
Copy link
Contributor

brumik commented Dec 19, 2021

Since 2020 the security of the electron apps require recommend a preload function. To use this lib with preload it could export the preload function.
I am able to make the pull request, it is just a questions if I should?

Export somehow this function

contextBridge.exposeInMainWorld('api', {
  send: (channel: string, requestId: string, action: string, payload: any): void => {
    const validChannel = ['asyncRequest'];
    if (validChannel.includes(channel)) {
      ipcRenderer.send(channel, requestId, action, payload);
    }
  },
  on: (channel: string, callback: Function): void => {
    const validChannel = [
      'asyncResponseNotify',
      'asyncResponse',
      'errorResponse',
    ]
    if (validChannel.includes(channel)) {
      // Strip event but pass an empty object to the callback
      ipcRenderer.on(channel, (_event, ...args) => callback({}, ...args));
    }
  }  
});

So the user can do:

// preload.ts
import electron from 'electron';
import { generatePreload } from 'eiphop';

generatePreload(electron);
@shivekkhurana
Copy link
Member

Can you post a link to some docs? I don't know about this update.
In general, I'm always looking for enhancements to this project. But I feel that introducing this API will break existing projects, so we'll have to do a major release.

@brumik
Copy link
Contributor Author

brumik commented Dec 19, 2021

I don't think this is a breaking change, it's an extra function for the current release, I would call it a feature in schematic versioning.

Here is the post I found really useful, why is good to use the contextBridge:
electron/electron#9920 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants