I have an Ionic app. It's works well for a couple of weeks, then it stops. I get the splash screen followed by the white screen of death. When I debug using chrome://inspect into the app I get the following message in the console:
No Content-Security-Policy meta tag found. Please add one when using the cordova-plugin-whitelist plugin.
If I clear all data on my app, it starts working, and I get the same message when I debug a working app on another device, so I don't think it's the plugin at fault. However, I have used the plugin to explore the white-screen problem, because I can get the white screen of death if I add the following to my index.html
(a content security policy that prevents loading resources from any source):
<meta http-equiv="Content-Security-Policy" content="default-src 'none'">
When I do that, I get error messages like this in the console:
Refused to load the stylesheet 'file:///android_asset/www/lib/ionic/css/ionic.min.css' because it violates the following Content Security Policy directive: "default-src 'none'". Note that 'style-src' was not explicitly set, so 'default-src' is used as a fallback
And when I change the tag to this:
<meta http-equiv="Content-Security-Policy" content="default-src 'self'">
I get this in my console:
Refused to apply inline style because it violates the..etc
And I also get
EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script...etc"
But now, instead of a white screen, my exception handler is catching the problem and reporting it.
From this, I deduce that the absence of files causes my white screen, because my exception handler works if all files are loaded.
I can get rid of all errors in my console using this security policy:
<meta http-equiv="Content-Security-Policy"
content="style-src 'self' ionic.bundle.min.js 'unsafe-inline';
script-src 'self' console-via-logger.js 'unsafe-eval';
img-src 'self' ionic.bundle.min.js data:">
So I am wondering if there is a way to catch the exception in my application at an earlier stage so that I can diagnose the original white-screen problem? I think it must be something in the data preventing a file being loaded, but how could that be?