0

I'm using Sentry to catch errors on my platform (CakePHP 2.*), and I'm given the following error:

TypeError ?(clients/view/1998667)
ยท Object http://192.168.1.130/clients/view/1998667 has no method 'includes'

I figured neither String nor Array objects in this version of browser had the Object.prototype.includes function defined, so I added it before any script that could potentially use this object method (before libraries and custom code).

(Not perfect functions but should do the trick for my use-case).

if (String.prototype.includes === undefined)
{
    console.log('String.prototype.inclues is UNDEFINED');

    String.prototype.includes = function(word){
        return this.toLowerCase().indexOf(word.toLowerCase()) > -1;
    }
}

if (Array.prototype.includes === undefined)
{
    console.log('Array.prototype.inclues is UNDEFINED');

    Array.prototype.includes = function(search){
        var includes = false;

        this.forEach(function(item){
            if (item === search)
            {
                includes = true;

                return includes;
            }
        });

        return includes;
    }
}

The weird thing is; even when I'm running Android with API 16 on my emulator, Sentry keeps catching the error and the view does not work as it should, and I'm unable to catch the error in my Android code.

I even tested in Safari with the same User Agent from Android's WebView Mozilla/5.0 (Linux; U; Android 4.1.2; en-us; Android SDK built for x86 Build/MASTER) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30

Android code for console messages:

webView.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
         android.util.Log.d("WebView", consoleMessage.message());

         return true;
    }
});

My question is: How can I catch JavaScript errors in Android Java and what am I not doing right for the defined functions to work?

Salines
  • 5,674
  • 3
  • 25
  • 50
James
  • 679
  • 1
  • 8
  • 22

1 Answers1

0

Sentry Android SDK won't detect any JS errors, but you could do something similar to Detecting Webview Error and Show Message

Adding a callback to your webview (eg onReceivedError), create an Exception or SentryEvent out of the errorCode, description... and call Sentry.captureException(e) manually.

Manoel Neto
  • 158
  • 4