最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Android webview crash "Fatal signal 5 (SIGTRAP)" - Stack Overflow

programmeradmin3浏览0评论

I have an app with a web view in which I load HTML content with JavaScript enabled. The web view is inside a fragment.

This is how I initialize the web view inside the method onCreateView of the fragment :

WebView webview = (WebView) mainView.findViewById(R.id.webview);

WebSettings webSettings = webview.getSettings();

webSettings.setJavaScriptEnabled(true);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);

webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        /*
        * My code
        */
    }
});

webview.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
        WebView.HitTestResult result = view.getHitTestResult();
        String data = result.getExtra();
        if (data != null) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
            startActivity(browserIntent);
        }
        return false;
    }
});

webview.loadDataWithBaseURL(baseUrl, htmlData, "text/html", "utf-8", "");

In the web view, a map is loaded with JavaScript. On this map, we can click on elements and load photos. When clicked, the photo is displayed in a popup (still inside the web view). When I click on the back button to go back to the map, the app crashes.

Here is the error log :

A/libc: Fatal signal 5 (SIGTRAP), code 1 in tid 949 (Chrome_InProcRe) [ 03-21 11:26:08.510 364: 364 W/ ] debuggerd: handling request: pid=32610 uid=10289 gid=10289 tid=949

I tested and got the crash on Android 7.1.1, 6.0.1, 5.0.2. Then I tried with Android 4.4.2 and the app didn't crash.

When I click on the back button (as we can see on the GIF), it should go back to the previous state with the popup closed

I have an app with a web view in which I load HTML content with JavaScript enabled. The web view is inside a fragment.

This is how I initialize the web view inside the method onCreateView of the fragment :

WebView webview = (WebView) mainView.findViewById(R.id.webview);

WebSettings webSettings = webview.getSettings();

webSettings.setJavaScriptEnabled(true);
webSettings.setDisplayZoomControls(false);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setBuiltInZoomControls(true);
webSettings.setDomStorageEnabled(true);
webSettings.setSupportMultipleWindows(true);

webview.setWebViewClient(new WebViewClient() {
    @Override
    public void onPageFinished(WebView view, String url) {
        super.onPageFinished(view, url);
        /*
        * My code
        */
    }
});

webview.setWebChromeClient(new WebChromeClient() {
    @Override
    public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
        WebView.HitTestResult result = view.getHitTestResult();
        String data = result.getExtra();
        if (data != null) {
            Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(data));
            startActivity(browserIntent);
        }
        return false;
    }
});

webview.loadDataWithBaseURL(baseUrl, htmlData, "text/html", "utf-8", "");

In the web view, a map is loaded with JavaScript. On this map, we can click on elements and load photos. When clicked, the photo is displayed in a popup (still inside the web view). When I click on the back button to go back to the map, the app crashes.

Here is the error log :

A/libc: Fatal signal 5 (SIGTRAP), code 1 in tid 949 (Chrome_InProcRe) [ 03-21 11:26:08.510 364: 364 W/ ] debuggerd: handling request: pid=32610 uid=10289 gid=10289 tid=949

I tested and got the crash on Android 7.1.1, 6.0.1, 5.0.2. Then I tried with Android 4.4.2 and the app didn't crash.

When I click on the back button (as we can see on the GIF), it should go back to the previous state with the popup closed

Share Improve this question edited Oct 15, 2021 at 23:42 user17147277 asked Mar 21, 2017 at 11:11 EddybrtnEddybrtn 7435 silver badges9 bronze badges 9
  • 3 do you test on device or emulator? please set an webchromeclient before loadDataWithBaseUrl() like this: webview .setWebChromeClient(new WebChromeClient()); – A.D. Commented Mar 21, 2017 at 12:09
  • 1 And for Javascript debbugging it's good to override onConsoleMessage in WebChromeClient – A.D. Commented Mar 21, 2017 at 12:18
  • 1 @user2281606 It works fine on emulator. Also, I was already setting a webchrome client. I edited the code in my question. I tried to see the logs with remote debugging developers.google.com/web/tools/chrome-devtools/… but there is no logs – Eddybrtn Commented Mar 21, 2017 at 12:57
  • 3 Did you ever solve this @Eddybrtn? I'm seeing the same. I think it relates to hardware acceleration being enabled, because when I disable hardware acceleration these crash reports disappear... but then my "slow rendering" metric goes through the roof... stuck between a rock and a hard place :-( – drmrbrewer Commented Nov 23, 2017 at 14:51
  • 3 @drmrbrewer I guess we'll never know – Denny Commented Aug 10, 2018 at 17:28
 |  Show 4 more comments

2 Answers 2

Reset to default 1

Try to override the back navigation functionality and close the popup yourself.

You don't need to handle all the stack navigation logic, just have a state when you are showing this popup. Apply your own navigation logic(like manually closing the popup).

void onBackPressed(){
    if(isTheBuggyPopupIsOn){
        closeTheBuggyPopup();
    }
    else{
        super.onBackPressed();
    }
}

Try this....

First add this

webView.setWebViewClient(new MyBrowser());

and then add this

public class MyBrowser extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            // TODO Auto-generated method stub

            if (url.equals(""YOUR URL)) {
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                startActivity(intent);
                return true;
            } else {
                return false;
            }

        }

    }
发布评论

评论列表(0)

  1. 暂无评论