[英]How to crash an Android Webview?
I am testing an Android crash reporting tool and would like to see how it responds to crashes coming from WebViews - ie from the HTML/JavaScript/CSS code running in them. 我正在测试一个Android崩溃报告工具,希望了解它如何响应来自WebView的崩溃-即来自运行于其中的HTML / JavaScript / CSS代码。
My question is how to produce such a crash. 我的问题是如何产生这种崩溃。
From the app side, you can do: 从应用程序方面,您可以执行以下操作:
mWebView.loadUrl("chrome://crash");
Note that you can't do that from JS / HTML code directly -- the request for this URL must come from the browser side. 请注意,您不能直接从JS / HTML代码中执行此操作-此URL的请求必须来自浏览器端。 But you can use Java Bridge to receive a command from the JS side: 但是您可以使用Java Bridge从JS端接收命令:
class WebViewCrasher {
@JavascriptInterface
public void crash() {
// post a task to UI thread to load "chrome://crash"
}
}
mWebView.addJavascriptInterface(new WebViewCrasher(), "crasher");
Then in your JS code you can call: 然后,在您的JS代码中,您可以调用:
crasher.crash();
But make sure you are not injecting this object in the release version of your app :) 但是请确保您没有在应用的发行版本中注入此对象:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.