【求助】electron打包后启动,后台log一直报关于ProtocolDeprecateCallback的错该如何解决?

最近发现electron的生产环境中打包后启动,后台log一直报这个错,在网上搜索解决方案,都无疾而终,关键electron版本更新太快,关于各版本的变动也比较大,很难找到适合自己版本的解决方案,就是搜索到的很少的方案也都试过了,这个error一直出现,虽然目前没发现有明显的影响,但毕竟是个错误,谁知道会有什么坑存在,很是头疼。

Electron版本:15.5.7
Node版本:14.18.3

关于protocol的代码片断:

protocol.registerSchemesAsPrivileged([
    { scheme: 'app', privileges: { secure: true, standard: true, bypassCSP: true } },
]);

function registerLocalResourceProtocol() {
    protocol.registerFileProtocol('local-resource', (request, callback) => {
        const url = request.url.replace(/^local-resource:\/\//, '')
        // Decode URL to prevent errors when loading filenames with UTF-8 chars or chars like "#"
        const decodedUrl = decodeURI(url) // Needed in case URL contains spaces
        try {
            return callback(decodedUrl)
        } catch (error) {
            console.error('ERROR: registerLocalResourceProtocol: Could not get file path:', error)
        }
    });
    protocol.registerFileProtocol('file', (request, callback) => {
        const pathname = decodeURIComponent(request.url.replace('file:///', ''));
        callback(pathname);
    });
}

// baidu地图api返回值导致存在bdapi://的请求,需要自定义此Protocol用来接收处理,否则系统将弹出【需要使用新应用以打开此bdapi链接】的openwith弹窗
function registerBdapiProtocol() {
    protocol.registerStringProtocol('bdapi', (request, callback) => {
        const decodedUrl = decodeURI(request.url) // Needed in case URL contains spaces
        console.log("bdapi:// Requested: " + decodedUrl);
        try {
            return callback(decodedUrl);
        } catch (error) {
            console.error('ERROR: registerStringProtocol: Could not get request url:', error);
        }
    })
}

报错信息:
[error] (node:26288) ProtocolDeprecateCallback: The callback argument of protocol module APIs is no longer needed.

注:由于官网上也没有例子,试着把callback去掉,改为Promise.resolve(decodedUrl)和Promise.reject(error),return去掉等等也不好用

希望Electron相关大神能指点迷津~感谢!!

================================================================================================
【后续】通过GPT-4.0给的各种建议,尝试后依然报同样的错误,最终告诉我可以暂时考虑忽略它 (; ̄ー ̄川

在这里插入图片描述
在这里插入图片描述
鉴于此版本的代码提示中还带有callback,暂且回退到上文的原始版本,待后续到github的electron社区发issue,官方回应后再回来更贴吧
在这里插入图片描述

  • 9
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值