Electron 自定义协议:“未注册处理程序”错误

2023-12-19

更新:我已经能够使网站重定向,但我的电子应用程序尚无法拦截该操作。这在开发中可能吗?我问过这个问题here https://stackoverflow.com/questions/68838012/does-electrons-registerhttpprotocol-work-in-development.


我正在尝试使用电子注册自定义协议。我希望它成为网站可以用来提供 api 密钥的重定向位置(例如myprotocol://example/payload=api-key).

但是当网站尝试重定向到我的协议时,它一直说:failed to launch myprotocol://example/payload=key... because the scheme does not have a registered handler。我需要做什么才能使这项工作成功?

我希望能够在生产和开发中实现这一点。

我看过讨论here https://stackoverflow.com/questions/56202191/how-to-integrate-oauth-login-with-a-packaged-electron-app和评论here https://stackoverflow.com/questions/64530295/what-redirect-uri-should-i-use-for-an-authorization-call-used-in-an-electron-app。遵循电子文档here https://www.electronjs.org/docs/api/protocol,这是我尝试过的:

main.js:

const { app, protocol } = require('electron')
    
app.whenReady().then(() => {
   protocol.registerFileProtocol('myprotocol', (request, callback) => {
      console.log('It worked! The website is sending this url: ' + request.url)
   }, (error) =>{
      if (error) console.log('Did not register the protocol')
   })
})

重定向 uri 提供给网站:

'myprotocol://example'

我已经能够将其列入白名单myprotocol://example在网站上。

但是,当网站尝试重定向到此协议时,我的电子应用程序不会注册任何活动,并且网站上的网络检查器显示错误:failed to launch myprotocol://example/payload=key... because the scheme does not have a registered handler.

我还尝试过其他方法,比如registerSchemesAsPrivileged and registerHttpProtocol, 没有成功。

有任何想法吗?


None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Electron 自定义协议:“未注册处理程序”错误 的相关文章

随机推荐