vrijdenker
vrijdenker

Reputation: 1431

Cordova whitelist plugin manually detect blocked navigation (event)

I am building an Ionic app using the cordova-whitelist-plugin to whitelist only certain URL's for navigation.

This is working fine, however I would like to detect when and which URL is being blocked by the plugin. I know that (at least in Xcode) a log appears when a URL is being blocked, but I am looking for some kind of JavaScript event to detect it.

I am pretty sure that there is no Cordova-Whitelist-Plugin javascript API available, but I might be overlooking something.

So my question is: Does anyone know if there is a way to detect a blocked (by the cordova-whitelist-plugin) navigation in JavaScript?

Upvotes: 0

Views: 266

Answers (1)

Brian Lukis
Brian Lukis

Reputation: 81

In the absence of other answers, an indirect answer:

cordova-plugin-whitelist recommends migrating to "Content Security Policy" meta tag instead of plugin functionality. https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-whitelist/

Content Security Policy request violations have an event like you're asking about, but seems to only work when using <meta http-equiv="Content-Security-Policy">. Not with the cordova-plugin-whitelist plugin.

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

(I also would like a similar event that works with the plugin.)

Upvotes: 2

Related Questions