Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android WebView: crash after url loading

When loading an url with my webView, application crashes after few seconds (without error log...).

My Code :

 wv = new WebView(this);
        wv.clearCache(true);
        wv.clearHistory();
        wv.getSettings().setJavaScriptEnabled(true);
        wv.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);

        wv.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent,
                                        String contentDisposition, String mimetype, long contentLength) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setType(mimetype);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        });


        wv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {

                // TODO change for other domains
                URL nextUrl;
                try {
                    nextUrl = new URL(url.toString());
                }catch (MalformedURLException e){
                    nextUrl = null;
                }

                if(nextUrl !=null && nextUrl.getHost().toString().equals(DOMAIN)) {
                    Toast.makeText(mContext, nextUrl.getHost().toString(), Toast.LENGTH_SHORT).show();
                    view.loadUrl(url);
                    return false;

                }else{
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                    startActivity(browserIntent);
                    return true;
                }

            }
        });

        wv.setWebChromeClient(new WebChromeClient() {
            public void onProgressChanged(WebView view, int progress) {
                MainActivity.this.setProgress(progress * 1000);
            }
            public boolean onConsoleMessage(ConsoleMessage cm) {
                Log.d("MyProject: WebView: ", cm.message() + " -- From line "
                    + cm.lineNumber() + " of "
                    + cm.sourceId() );
            return true;
        }
        });

        wv.loadUrl(URL);
        setContentView(wv);

Log :

01-20 18:00:50.798    7233-7288/ my.appli.com I/dalvikvm﹕ "WebViewCoreThread" prio=5 tid=12 NATIVE
01-20 18:00:50.798    7233-7288/ my.appli.com I/dalvikvm﹕ | group="main" sCount=0 dsCount=0 obj=0x419a0be0 self=0x68f6c750
01-20 18:00:50.798    7233-7288/ my.appli.com I/dalvikvm﹕ | sysTid=7288 nice=10 sched=0/0 cgrp=apps/bg_non_interactive handle=1773204176
01-20 18:00:50.799    7233-7288/ my.appli.com I/dalvikvm﹕ | state=R schedstat=( 0 0 0 ) utm=2326 stm=119 core=0
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #00  pc 000012a0  /system/lib/libcorkscrew.so (unwind_backtrace_thread+27)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #01  pc 0006235c  /system/lib/libdvm.so (dvmDumpNativeStack(DebugOutputTarget const*, int)+35)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #02  pc 000561bc  /system/lib/libdvm.so (dvmDumpThreadEx(DebugOutputTarget const*, Thread*, bool)+303)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #03  pc 00056256  /system/lib/libdvm.so (dvmDumpThread(Thread*, bool)+25)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ #04  pc 000478c8  /system/lib/libdvm.so (dvmDebuggerSignalHandler(int, siginfo*, void*)+15)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.sharedTimerFired(Native Method)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.fireSharedTimer(JWebCoreJavaBridge.java:92)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.JWebCoreJavaBridge.handleMessage(JWebCoreJavaBridge.java:108)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.os.Handler.dispatchMessage(Handler.java:99)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.os.Looper.loop(Looper.java:137)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:900)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ at java.lang.Thread.run(Thread.java:856)
01-20 18:00:50.841    7233-7288/ my.appli.com I/dalvikvm﹕ [ 01-20 18:00:50.841  7233: 7288 F/libc     ]
    Fatal signal 11 (SIGSEGV) at 0x0000001c (code=1), thread 7288 (WebViewCoreThre)

I've experienced the same issue(crash) when trying to load the same URL with the default browser of my android device(4.1).

The URL I want to load is :

http://presentbox.jp

Thank you for your help.

--- EDIT 1

I' ve tried with a recent android phone (4.4) and application didn't crashed.

For debug purpose, I've deleted all heavy parts of my website (images, js,...) but application still crash after scrolling down.

like image 412
johann Avatar asked Mar 13 '23 13:03

johann


2 Answers

// Edit: Found it! The culprit in on line 2540 in general.css:

#head-search-form{display: block;margin: 30px 0;}

More specifically, it's display: block that somehow makes the WebView choke. I'm not much of a web developer, but exchanging the value with flex or none seems to no longer result in a crash (and I couldn't tell the visual difference on a mobile device). Hope that helps!


I've set up a small test project and have been able to reproduce the crash on a (virtual) Android 4.1 device. It only seems to happens upon scrolling, after the page has fully loaded. I.e. you can expand the menu drawer without any issues, as long as you don't start scrolling...

I was able to narrow down the culprit to general.css. As soon as you don't load that style sheet, the page will work and scroll just fine, but of course won't look very pretty.

Since general.css counts 3300+ lines, I'd suggest you start your search for the actual cause by fixing the errors indicated by the W3C CSS Validator. If that doesn't solve the issue, start disabling style rules related to the photo grid, especially anything that involves animation/transformation. If I can find the time, I may have a go at this myself too.

Just for your information, here's a more extensive stack trace. Someone else may be able to find some more pointers in there too.

mh.test.webview A/libc: Fatal signal 11 (SIGSEGV) at 0x00001f08 (code=1), thread 11949 (WebViewCoreThre)
I/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
I/DEBUG: Build fingerprint: 'generic/vbox86p/vbox86p:4.1.1/JRO03S/eng.buildbot.20151117.133415:userdebug/test-keys'
I/DEBUG: pid: 11930, tid: 11949, name: WebViewCoreThre  >>> mh.test.webview <<<
I/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00001f08
I/DEBUG:     eax b84902e4  ebx 9ba8b488  ecx b804b028  edx b83c0224
I/DEBUG:     esi b8490360  edi b804b028
I/DEBUG:     xcs 00000073  xds 0000007b  xes 0000007b  xfs 00000000  xss 0000007b
I/DEBUG:     eip 00001f08  ebp 997b9748  esp 997b96dc  flags 00010296
I/DEBUG:     #00  pc 00001f08  <unknown>
I/DEBUG:     #01  pc 00344fd6  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+38)
I/DEBUG:     #02  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #03  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #04  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #05  pc 003454bb  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::computeCompositingRequirements(WebCore::RenderLayer*, WTF::HashMap<WebCore::RenderLayer*, WebCore::IntRect, WTF::PtrHash<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::RenderLayer*>, WTF::HashTraits<WebCore::IntRect> >*, WebCore::CompositingState&, bool&)+1291)
I/DEBUG:     #06  pc 00346c55  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::updateCompositingLayers(WebCore::CompositingUpdateType, WebCore::RenderLayer*)+213)
I/DEBUG:     #07  pc 0020e727  /system/lib/libwebcore.so (WebCore::FrameView::layout(bool)+1159)
I/DEBUG:     #08  pc 0068126f  /system/lib/libwebcore.so (WebCore::Document::updateLayout()+127)
I/DEBUG:     #09  pc 0068bbda  /system/lib/libwebcore.so (WebCore::Document::updateLayoutIgnorePendingStylesheets()+90)
I/DEBUG:     #10  pc 005ead53  /system/lib/libwebcore.so (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue(int, WebCore::EUpdateLayout) const+467)
I/DEBUG:     #11  pc 005f35e9  /system/lib/libwebcore.so (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue(int) const+41)
I/DEBUG:     #12  pc 005e68d7  /system/lib/libwebcore.so (WebCore::CSSComputedStyleDeclaration::getPropertyValue(int) const+55)
I/DEBUG:     #13  pc 006297f8  /system/lib/libwebcore.so (WebCore::CSSStyleDeclaration::getPropertyValue(WTF::String const&)+88)
I/DEBUG:     #14  pc 004d9475  /system/lib/libwebcore.so (WebCore::CSSStyleDeclarationInternal::getPropertyValueCallback(v8::Arguments const&)+181)
I/DEBUG:     #15  pc 000efdd4  <unknown>
I/DEBUG:     #16  pc 0005cf6b  <unknown>
I/DEBUG:     #17  pc 000bb32f  <unknown>
I/DEBUG:     #18  pc 00003b41  <unknown>
I/DEBUG:     #19  pc 000f47ce  <unknown>
I/DEBUG:     #20  pc 0001a5a3  <unknown>
I/DEBUG:     #21  pc 000065e3  <unknown>
I/DEBUG:     #22  pc 00003b41  <unknown>
I/DEBUG:     #23  pc 00024c59  <unknown>
I/DEBUG:     #24  pc 00024dad  <unknown>
I/DEBUG:     #25  pc 00003b41  <unknown>
I/DEBUG:     #26  pc 0001a59c  <unknown>
I/DEBUG:     #27  pc 000d7172  <unknown>
I/DEBUG:     #28  pc 0001a5a3  <unknown>
I/DEBUG:     #29  pc 000d40ed  <unknown>
I/DEBUG:     #30  pc 00017bf9  <unknown>
I/DEBUG:     #31  pc 00008c2a  <unknown>
I/DEBUG:          997b969c  00000000  
I/DEBUG:          997b96a0  00000000  
I/DEBUG:          997b96a4  00000000  
I/DEBUG:          997b96a8  00000000  
I/DEBUG:          997b96ac  00000000  
I/DEBUG:          997b96b0  00000000  
I/DEBUG:          997b96b4  00000000  
I/DEBUG:          997b96b8  00000000  
I/DEBUG:          997b96bc  00000000  
I/DEBUG:          997b96c0  00000000  
I/DEBUG:          997b96c4  00000000  
I/DEBUG:          997b96c8  00000000  
I/DEBUG:          997b96cc  00000000  
I/DEBUG:          997b96d0  00000000  
I/DEBUG:          997b96d4  00000000  
I/DEBUG:          997b96d8  00000000  
I/DEBUG:     #00  997b96dc  9ad1cdd4  /system/lib/libwebcore.so (WebCore::RenderLayer::updateLayerPosition()+52)
I/DEBUG:          997b96e0  b84902e4  [heap]
I/DEBUG:          997b96e4  b8490090  [heap]
I/DEBUG:          997b96e8  0000000f  
I/DEBUG:          997b96ec  0000002f  
I/DEBUG:          997b96f0  b8490090  [heap]
I/DEBUG:          997b96f4  00000001  
I/DEBUG:          997b96f8  9ad2204e  /system/lib/libwebcore.so (WebCore::RenderLayer::repaintIncludingNonCompositingDescendants(WebCore::RenderBoxModelObject*)+14)
I/DEBUG:          997b96fc  b827f428  [heap]
I/DEBUG:          997b9700  9ba8b488  /system/lib/libwebcore.so
I/DEBUG:          997b9704  b8490090  [heap]
I/DEBUG:          997b9708  997b9748  [stack:11949]
I/DEBUG:          997b970c  9ad35d38  /system/lib/libwebcore.so (WebCore::RenderLayerCompositor::updateBacking(WebCore::RenderLayer*, WebCore::RenderLayerCompositor::CompositingChangeRepaint)+344)
I/DEBUG:          997b9710  b8490014  [heap]
I/DEBUG:          997b9714  b848fe3c  [heap]
I/DEBUG:          997b9718  00000012  
I/DEBUG:          ........  ........
I/DEBUG:     #01  997b9750  b8490360  [heap]
I/DEBUG:          997b9754  b8490090  [heap]
I/DEBUG:          997b9758  00000000  
I/DEBUG:          997b975c  997b98e0  [stack:11949]
I/DEBUG:          997b9760  997ba84f  [stack:11949]
I/DEBUG:          997b9764  b843a9e4  [heap]
I/DEBUG:          997b9768  00000034  
I/DEBUG:          997b976c  00000180  
I/DEBUG:          997b9770  b848fe3c  [heap]
I/DEBUG:          997b9774  b85257f8  [heap]
I/DEBUG:          997b9778  9ace0300  /system/lib/libwebcore.so (WebCore::RenderBox::dirtyLineBoxes(bool)+80)
I/DEBUG:          997b977c  43400000  
I/DEBUG:          997b9780  b83fe51c  [heap]
I/DEBUG:          997b9784  997b9788  [stack:11949]
I/DEBUG:          997b9788  004a0000  
I/DEBUG:          997b978c  b848feb8  [heap]
I/DEBUG:          ........  ........
I/DEBUG:     #02  997b9aa0  b804b028  [heap]
I/DEBUG:          997b9aa4  b8490360  [heap]
I/DEBUG:          997b9aa8  00000000  
I/DEBUG:          997b9aac  997b9c30  [stack:11949]
I/DEBUG:          997b9ab0  997ba84f  [stack:11949]
I/DEBUG:          997b9ab4  b83fe51c  [heap]
I/DEBUG:          997b9ab8  00000000  
I/DEBUG:          997b9abc  00000001  
I/DEBUG:          997b9ac0  b86fd038  [heap]
I/DEBUG:          997b9ac4  b86fd368  [heap]
I/DEBUG:          997b9ac8  997b9b48  [stack:11949]
I/DEBUG:          997b9acc  9adac54a  /system/lib/libwebcore.so (WebCore::TransformState::move(int, int, WebCore::TransformState::TransformAccumulation)+58)
I/DEBUG:          997b9ad0  b83fe678  [heap]
I/DEBUG:          997b9ad4  b8294d4c  [heap]
I/DEBUG:          997b9ad8  00580b05  
I/DEBUG:          997b9adc  b83fe770  [heap]
I/DEBUG:          ........  ........
I/DEBUG:     (no map below)
I/DEBUG:     (no map for address)
I/DEBUG:     20c1e000-20c1f000 
like image 79
MH. Avatar answered Mar 24 '23 04:03

MH.


Are you are using a customized version of Android ? a specific mod? if you do - there is always a chance the problem is a result of that ROM. There have been cases where a WebView has experienced problems in specific version of Android or on specific ROMs. Some link: https://code.google.com/p/chromium/issues/detail?id=481420 http://googlechromereleases.blogspot.com.au/2015/04/android-webview-stable-update.html http://forum.xda-developers.com/verizon-htc-one-m8/help/android-webviewer-update-huge-turd-t3091192/post60333480#post60333480 Android System WebView crashes Android apps! "Tombstones are disabled on JB MR2+ user builds"

Check if you WebView is up to date. if it is - uninstall the updates and check if the problem is still there. If it's NOT up to date - do an update and check if the problem persist. most chances it won't.

In addition - this problem will probably not happen much. in most devices that I've worked with - WebView is reliable and stable.

good luck.

like image 38
FunkSoulBrother Avatar answered Mar 24 '23 06:03

FunkSoulBrother