如何在电子应用中使用Google的reCAPTCHA?

时间:2017-01-11 07:16:22

标签: electron recaptcha electron-builder

Google的reCAPTCHA是针对特定领域的,所以当在Github的电子应用中使用时,它会出现以下错误ERROR for site owner: Invalid domain for site key

可能是因为在电子应用程序中,文件加载了file:///协议,因此加载验证码时不会发送任何引用标头。我正在使用electron ./来运行该应用程序。

在电子应用程序中加载reCAPTCHA有什么解决方案吗?

2 个答案:

答案 0 :(得分:0)

使用express托管本地服务器,然后在main.js中将loadUrl(__dirname + 'index.html')函数编辑为loadUrl('http://localhost:' + myLocalServerPort)

答案 1 :(得分:-1)

我遇到了同样的问题,例如user9699066,我不得不使用快速服务器,因为它无法使用file://协议。

这是我的代码:

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`));

然后reCaptcha运行良好。

相关问题