7

Google's reCAPTCHA is domain specific so when used in an Github's electron app, it gives the following error ERROR for site owner: Invalid domain for site key.

Possibly because in an electron app the files are loaded with file:/// protocol and hence no referer header is sent when the captcha is loaded. I am using electron ./ to run the application.

Is there any solution for loading reCAPTCHA in an electron app?

BiJ
  • 1,639
  • 5
  • 24
  • 55
  • You can disable the domain validation in the recaptcha configuration, and then it will load without problems. However, when you try to validate the recaptcha, it will get a different error: recaptcha__es.js:338 Uncaught SecurityError: Blocked a frame with origin "https://www.google.com" from accessing a frame with origin "file://". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "file". Protocols must match. – Alvaro Luis Bustamante Jan 15 '17 at 15:54
  • @AlvaroLuisBustamante are you sure that disabling "domain validation" will resolve the problem? For me it didn't make any difference! BTW, I'm using recaptcha with cordova. It also uses file:/// protocol – Alireza Mirian May 28 '17 at 08:19

2 Answers2

0

I had the same issue, like said user9699066, I had to use an express server since it's not working using file:// protocol.

Here's my code:

const express = require('express');
const server = express();

server.use('/', express.static(__dirname));
const infos = server.listen(0, 'localhost', () => win.loadURL(`http://localhost:${infos.address().port}/dist/index.html`));

Then reCaptcha is working well.

Romain-p
  • 518
  • 2
  • 9
  • 26
-1

Use express to host a local server and in the main.js edit the loadUrl(__dirname + 'index.html')function to loadUrl('http://localhost:' + myLocalServerPort)