Logging JavaScript errors in an Apache Cordova or PhoneGap App

Apache Cordova apps are simply JavaScript applications embedded in a WebView and published to an Apple iOS or Google Android application.

Because they are just JavaScript, it is very easy to implement ErrLog.IO

Application Structure

At Kutamo, we typically use Adobe PhoneGap to construct and build our Cordova applications. The file structure for these is almost identical to other implementations of Cordova.

Apache Cordova File Structure

The index.html file is the basis for the application, and ErrLog.IO is inserted in the file as it would for any traditional web site.

<!DOCTYPE html>

        <script type="text/javascript" src="cordova.js"></script>

        <!-- ErrLog.IO -->
        <script async src="https://relay.errlog.io/js/v1?apikey=[Your-api-key]"></script>

Application Security Policy - Content-Security-Policy

Cordova applications use a meta-tag called Content-Security-Policyto define security policies for the application itself, and specifically what domains and resources the application is able to access.

Content-Security-Policy support is a native browser capability that allows you to control exactly what content your app can access and at a very granular level. In fact, when using the CSP, you can generally keep the access origin to "*" as you'll be able to more tightly control security using the policy.

A Content-Security-Policy is applied at a page level through a few different mechanisms, but for Cordova apps you typically use a meta tag.

To enable your Cordova application to communicate with ErrLog.IO, you just need to add our URL to the script-src component of the meta tag.


<meta http-equiv="Content-Security-Policy" 
    content="...your security policies... 
    script-src 'self' 'unsafe-inline' 'unsafe-eval' https://relay.errlog.io/ ">

Microsoft have a comprehensive guide on the policy tags here

Recent Posts

Jan, 2022
Dec, 2021
Nov, 2021
Oct, 2021
Sep, 2021
Aug, 2021
Jun, 2021
Jan, 2021
Mar, 2020
Feb, 2020
Jun, 2018
May, 2018
Feb, 2018
Dec, 2017
Nov, 2017
Oct, 2017
Sep, 2017


Discuss this article