gpt4 book ai didi

javascript - 安卓 WebView : crash after url loading

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:27:28 26 4
gpt4 key购买 nike

当用我的 webView 加载一个 url 时,应用程序在几秒钟后崩溃(没有错误日志...)。

我的代码:

 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);

日志:

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)

尝试使用我的 Android 设备 (4.1) 的默认浏览器加载相同的 URL 时,我遇到了同样的问题(崩溃)。

我要加载的 URL 是:

http://presentbox.jp

感谢您的帮助。

--- 编辑 1

我用最近的 Android 手机 (4.4) 试过,应用程序没有崩溃。

出于调试目的,我删除了我网站的所有重要部分(图像、js 等),但应用程序在向下滚动后仍然崩溃。

最佳答案

//编辑:找到了! general.css 中第 2540 行的罪魁祸首:

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

更具体地说,是 display: block 以某种方式使 WebView 阻塞。我不是网络开发人员,但是用 flexnone 交换值似乎不再导致崩溃(而且我无法分辨视觉差异在移动设备上)。希望对您有所帮助!


我已经建立了一个小型测试项目,并且能够在(虚拟)Android 4.1 设备上重现崩溃。它似乎只在页面完全加载后滚动时发生。 IE。您可以毫无问题地展开菜单抽屉,只要您不开始滚动...

我能够将罪魁祸首缩小到 general.css .只要您不加载该样式表,页面就会正常工作和滚动,但当然看起来不会很漂亮。

由于 general.css 有 3300 多行,我建议您通过修复 the errors indicated by the W3C CSS Validator 来开始搜索真正的原因。 .如果这不能解决问题,请开始禁用与照片网格相关的样式规则,尤其是涉及动画/转换的任何内容。如果我有时间,我也可以自己尝试一下。

仅供引用,这里有一个更广泛的堆栈跟踪。其他人也可以在那里找到更多的指示。

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

关于javascript - 安卓 WebView : crash after url loading,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34895838/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com