【发布时间】:2020-03-09 19:41:55
【问题描述】:
我正在使用Sentry 在我的平台 (CakePHP 2.*) 上捕获错误,我收到以下错误:
TypeError ?(clients/view/1998667)
· Object http://192.168.1.130/clients/view/1998667 has no method 'includes'
我发现这个版本的浏览器中的String 和Array 对象都没有定义Object.prototype.includes 函数,所以我在任何可能使用此对象方法的脚本之前添加了它(在库和自定义代码之前)。
(不是完美的功能,但应该适合我的用例)。
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;
}
}
奇怪的是;即使我在模拟器上运行Android with API 16,Sentry 仍会不断捕获错误,并且视图无法正常工作,并且我无法在我的 Android 代码中捕获错误。
我什至在 Safari 中使用来自 Android 的 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代码:
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
android.util.Log.d("WebView", consoleMessage.message());
return true;
}
});
我的问题是:如何在 Android Java 中捕获 JavaScript 错误,以及我在哪些方面做得不对以使定义的函数正常工作?
【问题讨论】:
标签: javascript android webview sentry