Cordova白名单插件手动检测阻塞导航(事件)

Cordova whitelist plugin manually detect blocked navigation (event)

本文关键字:检测 导航 事件 插件 白名单 名单 Cordova      更新时间:2023-09-26

我正在构建一个Ionic应用程序,使用cordova-whitelist-plugin只将某些URL的导航白名单。

这是工作很好,但我想检测何时和哪个URL被插件阻止。我知道(至少在Xcode中)当URL被阻止时出现日志,但我正在寻找某种JavaScript事件来检测它。

我很确定没有Cordova-Whitelist-Plugin javascript API可用,但我可能忽略了一些东西。

我的问题是:有没有人知道,如果有一种方法来检测阻塞(由cordova-whitelist-plugin)导航在JavaScript?

在没有其他答案的情况下,采用间接回答:

cordova-plugin-whitelist建议迁移到"Content Security Policy"元标签而不是插件功能。https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/

内容安全策略请求违规具有您正在询问的事件,但似乎仅在使用<meta http-equiv="Content-Security-Policy">时有效。使用cordova-plugin-whitelist插件就不行。

document.addEventListener('securitypolicyviolation', function(e) {
    alert(JSON.stringify(e));
});

(我也想一个类似的事件,与插件的工作。)