electron icon indicating copy to clipboard operation
electron copied to clipboard

Capacitor-community/electron not working with https/http after capacitor library update from version 2 to 3.4

Open fahad-cinnova opened this issue 3 years ago • 6 comments

I have recently update the capacitor library for my ionic project. But after update the capacitor library my android and ios versions are working fine. But my windows version not working . I'm not able to send any http/https request.

I have update elector capacitor below From: "@capacitor-community/electron": "^1.4.2", To: "@capacitor-community/electron": "^4.1.0",

My others versions are below "@capacitor/core": "^3.4.3", "@capacitor/ios": "^3.4.3", "@capacitor/android": "^3.4.3", "@ionic/pwa-elements": "^3.0.2", "@ionic/angular": "^5.0.0",

Please let me know if anyone have an idea to resolve my problem. This is the screen shot of console. @IT-MikeS image

fahad-cinnova avatar Apr 18 '22 17:04 fahad-cinnova

Fix: Refused to connect to 'https://www.domain.com' because it violates the following Content Security Policy directive: "default-src capacitor-electron://*

File electron/src/setup.ts Line aprox: 229.

BEFORE

 'Content-Security-Policy': [
          electronIsDev
            ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
            : `default-src ${customScheme}://* 'unsafe-inline' data:`,
        ],

AFTER

'Content-Security-Policy': [
          electronIsDev
            ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' http://* 'unsafe-eval' https://* 'unsafe-eval' ws://* 'unsafe-eval' wss://* 'unsafe-eval' data:`
            : `default-src ${customScheme}://* 'unsafe-inline' http://* 'unsafe-eval' https://* 'unsafe-eval' ws://* 'unsafe-eval' wss://* 'unsafe-eval' data:`,
        ],

xgiral-metacodi avatar May 03 '22 15:05 xgiral-metacodi

Fix: Refused to connect to 'https://www.domain.com' because it violates the following Content Security Policy directive: "default-src capacitor-electron://*

File electron/src/setup.ts Line aprox: 229.

BEFORE

 'Content-Security-Policy': [
          electronIsDev
            ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
            : `default-src ${customScheme}://* 'unsafe-inline' data:`,
        ],

AFTER

'Content-Security-Policy': [
          electronIsDev
            ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' http://* 'unsafe-eval' https://* 'unsafe-eval' ws://* 'unsafe-eval' wss://* 'unsafe-eval' data:`
            : `default-src ${customScheme}://* 'unsafe-inline' http://* 'unsafe-eval' https://* 'unsafe-eval' ws://* 'unsafe-eval' wss://* 'unsafe-eval' data:`,
        ],

While this does work, it is not very secure. Your app would be more secure if you add the specific URL's to the CSP (or even better, if you just bundle the resource). This site could help: https://report-uri.com/home/generate.

jdgjsag67251 avatar Aug 02 '22 15:08 jdgjsag67251

Fix: Refused to connect to 'https://www.domain.com' because it violates the following Content Security Policy directive: "default-src capacitor-electron://*

File electron/src/setup.ts Line aprox: 229.

BEFORE

 'Content-Security-Policy': [
          electronIsDev
            ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' data:`
            : `default-src ${customScheme}://* 'unsafe-inline' data:`,
        ],

AFTER

'Content-Security-Policy': [
          electronIsDev
            ? `default-src ${customScheme}://* 'unsafe-inline' devtools://* 'unsafe-eval' http://* 'unsafe-eval' https://* 'unsafe-eval' ws://* 'unsafe-eval' wss://* 'unsafe-eval' data:`
            : `default-src ${customScheme}://* 'unsafe-inline' http://* 'unsafe-eval' https://* 'unsafe-eval' ws://* 'unsafe-eval' wss://* 'unsafe-eval' data:`,
        ],

While this does work, it is not very secure. Your app would be more secure if you add the specific URL's to the CSP (or even better, if you just bundle the resource). This site could help: https://report-uri.com/home/generate.

This helped me a lot, I just want to know how to add the specific url's to the Firebase Cloud Firestore, if you know how I would appreciate it, thanks anyway

viniciusnevescosta avatar Nov 27 '22 18:11 viniciusnevescosta

This doesn't always work. Especially on first time launch of the app. If you close and open it again, it may work.

The CSP settings aren't always applied. Perhaps it's a timing issue?

fromage9747 avatar Aug 01 '23 09:08 fromage9747

This doesn't always work. Especially on first time launch of the app. If you close and open it again, it may work.

The CSP settings aren't always applied. Perhaps it's a timing issue?

Are you tried on production complilation?

xgiral-metacodi avatar Aug 02 '23 08:08 xgiral-metacodi

@xgiral-metacodi Yup. App is built in production mode.

fromage9747 avatar Aug 02 '23 11:08 fromage9747