capacitor-community / electron

Deploy your Capacitor apps to Linux, Mac, and Windows desktops, with the Electron platform! 🖥️
https://capacitor-community.github.io/electron/
MIT License
318 stars 58 forks source link

Support for new Capacitor HTTP plugin? #209

Closed philjones88 closed 1 year ago

philjones88 commented 1 year ago

Is your feature request related to a problem? Please describe.

Is there a way to support the new Capacitor HTTP plugin they demoed at Q3 update?

See: https://youtu.be/NLHF3e4eMtA?t=1908

https://capacitorjs.com/docs/apis/http

I've tried adding it to my capacitor.config.json file but nothing seems to have changed and I still get CORS issues.

JuliusSkrisa commented 1 year ago

Its not supported, and I dont think its possible (or there is easy way) to support it. (to create http request in any other context then from the webview running under the electron platform) Since electron itself runs on multiple platforms.

philjones88 commented 1 year ago

In the end I just disabled CORS in electron setup.ts using:

// Set a CSP up for our application based on the custom scheme
export function setupContentSecurityPolicy(customScheme: string): void {
  session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
    callback({ requestHeaders: { Origin: '*', ...details.requestHeaders } });
  });

  session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
    callback({
      responseHeaders: {
        ...details.responseHeaders,
        'Access-Control-Allow-Origin': ['*'],
        'Access-Control-Allow-Headers': ['*'],
        // 'Content-Security-Policy': [
        //   electronIsDev
        //     ? `default-src ${customScheme}://* https://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
        //     : `default-src ${customScheme}://* https://* 'unsafe-inline' data:`,
        // ],
      },
    });
  });
}