How to debug webkit crash log in iOS - ios

We got crash log like this(Only crash on iOS 9):
Crashed: com.apple.main-thread
EXC_BAD_ACCESS 0x00000000815fe0fd
And detail
Crashed: com.apple.main-thread
0 WebKit 0x281aa862 std::__1::__function::__func<WebKit::WebsiteDataStore::fetchData(WebKit::WebsiteDataTypes, std::__1::function<void (WTF::Vector<WebKit::WebsiteDataRecord, 0ul, WTF::CrashOnOverflow, 16ul>)>)::$_0, std::__1::allocator<WebKit::WebsiteDataStore::fetchData(WebKit::WebsiteDataTypes, std::__1::function<void (WTF::Vector<WebKit::WebsiteDataRecord, 0ul, WTF::CrashOnOverflow, 16ul>)>)::$_0>, void (WebKit::WebsiteData)>::destroy_deallocate() + 29
1 libobjc.A.dylib 0x20a37e09 object_dispose + 20
2 WebKit 0x2808fbaf std::__1::__function::__func<WebKit::NetworkProcessProxy::fetchWebsiteData(WebCore::SessionID, WebKit::WebsiteDataTypes, std::__1::function<void (WebKit::WebsiteData)>)::$_0, std::__1::allocator<WebKit::NetworkProcessProxy::fetchWebsiteData(WebCore::SessionID, WebKit::WebsiteDataTypes, std::__1::function<void (WebKit::WebsiteData)>)::$_0>, void (WebKit::WebsiteData)>::destroy_deallocate() + 30
3 WebKit 0x280518d5 WTF::HashTable<unsigned long long, WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> > >, WTF::IntHash<unsigned long long>, WTF::HashMap<unsigned long long, std::__1::function<void (WebKit::WebsiteData)>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<std::__1::function<void (WebKit::WebsiteData)> > >::KeyValuePairTraits, WTF::HashTraits<unsigned long long> >::deallocateTable(WTF::KeyValuePair<unsigned long long, std::__1::function<void (WebKit::WebsiteData)> >*, unsigned int) + 48
4 WebKit 0x2808f449 WebKit::NetworkProcessProxy::networkProcessCrashedOrFailedToLaunch() + 252
5 JavaScriptCore 0x246f7a4f WTF::RunLoop::performWork() + 310
6 JavaScriptCore 0x246f7ebb WTF::RunLoop::performWork(void*) + 22
7 CoreFoundation 0x21255dff __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
8 CoreFoundation 0x212559ed __CFRunLoopDoSources0 + 452
9 CoreFoundation 0x21253d5b __CFRunLoopRun + 794
10 CoreFoundation 0x211a3229 CFRunLoopRunSpecific + 520
11 CoreFoundation 0x211a3015 CFRunLoopRunInMode + 108
12 GraphicsServices 0x22793ac9 GSEventRunModal + 160
13 UIKit 0x25877189 UIApplicationMain + 144
14 Our App 0x7187e5 main (main.m:20)
15 libdispatch.dylib 0x20e4b873 (Missing)
We use WKWebView to show some web page. And using WKUserContentController as bridge to do some call between H5 and Native.
So, how to debug this kind of crash?
I tried to read the source code of Webkit, but it is useless. I only figure out that the WebKit network process is about to exit when crash happened.

We tried to reload webview when WKKit process crashed, and the crash is gone。
- (void)webViewWebContentProcessDidTerminate:(WKWebView *)webView {
[_webView reload];
}

Related

Mapkit MapView VectorKit Crash on iOS13

As iOS13 release, there are more and more mapKit VectorKit crashes on the app which we are working on. We can not reproduce the crash internally and there are over 200 crashes collected by our own crash reporter everyday.
From all the information we have got, the crash always happens when the application come to active from background, and at that time, the ViewController view has a MKMapView subview. Maybe something wrong when the system rendering the map UI.
This problem seems a long-lasting iOS problem since iOS11 or even earlier. Now, The crash related iOS13 system version includes 13.0, 13.1, 13.1.1, 13.1.2. I have reported the problem on the Apple bug report system, but no any response from Apple until now.
Any advice or hint will be greatly appreciated.
FYI. The crash stack as below.
Exception Type: SIGABRT
Exception Codes: #0 at 0x1a8530ebc
Crashed Thread: 0
Thread 0 Crashed:
0 libsystem_kernel.dylib __pthread_kill + 8
1 libsystem_c.dylib abort + 100
2 libsystem_c.dylib __assert_rtn + 204
3 Metal MTLIOAccelCommandBufferStorageGrowSegmentList.cold.1 + 0
4 Metal MTLReportFailure + 476
5 Metal -[MTLTextureDescriptorInternal validateWithDevice:] + 2124
6 AGXMetalA11 0x00000001a85f93e8 + 64
7 VectorKit ggl::MetalResourceManager::newTexture(ggl::Texture const*) + 596
8 VectorKit ggl::MetalRenderer::prepareTexture(ggl::MetalResourceManager*, ggl::Texture const*) + 44
9 VectorKit ggl::MetalRenderer::_processQueue(ggl::RenderTarget*, ggl::RenderQueue*, id<MTLCommandBuffer>) + 3220
10 VectorKit ggl::MetalRenderer::_processQueue(ggl::RenderTarget*, ggl::RenderQueue*, id<MTLCommandBuffer>) + 96
11 VectorKit invocation function for block in ggl::MetalRenderer::frame(ggl::RenderTarget*, ggl::RenderQueue*, std::__1::function<void ()>, std::__1::function<void ()>) + 56
12 VectorKit invocation function for block in geo::TaskQueue::sync(std::__1::function<void ()>) + 60
13 libdispatch.dylib _dispatch_client_callout + 16
14 libdispatch.dylib _dispatch_async_and_wait_invoke_and_complete_recurse + 228
15 libdispatch.dylib _dispatch_async_and_wait_f + 100
16 VectorKit ggl::MetalRenderer::frame(ggl::RenderTarget*, ggl::RenderQueue*, std::__1::function<void ()>, std::__1::function<void ()>) + 544
17 VectorKit ggl::RenderFrame::execute(ggl::RenderTarget*, ggl::RenderQueue*, std::__1::function<void ()>, std::__1::function<void ()>) + 120
18 VectorKit -[MDDisplayLayer drawToTexture:withRenderQueue:completionHandler:] + 348
19 VectorKit -[MetalLayer _onTimerFired:withPresent:] + 280
20 VectorKit md::MapEngine::renderScene(double, std::__1::function<void ()>) + 104
21 VectorKit md::MapEngine::onRenderTimerFired(double) + 328
22 VectorKit ggl::DisplayLink::onTimerFired(double) + 40
23 VectorKit -[_GGLDisplayLinkTarget displayLinkFired:] + 84
24 QuartzCore CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 632
25 QuartzCore display_timer_callback(__CFMachPort*, void*, long, void*) + 264
26 CoreFoundation __CFMachPortPerform + 172
27 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56
28 CoreFoundation __CFRunLoopDoSource1 + 444
29 CoreFoundation __CFRunLoopRun + 2168
30 CoreFoundation CFRunLoopRunSpecific + 464
31 GraphicsServices GSEventRunModal + 104
32 UIKitCore UIApplicationMain + 1936
33 homebrew main (main.m:16)
34 libdyld.dylib start + 4
Check your CPU utilization on iOS12 vs iOS13.
I noticed that my app was crashing because I was adding and removing polylines to the map too frequently (although this problem only manifested in iOS13, not iOS12).
See my SO post about this here.
Look at your crash logs and see if you spot something like this:
Event: cpu usage
Action taken: Process killed
CPU: 48 seconds cpu time over 54 seconds (88% cpu average), exceeding limit of 80% cpu over 60 seconds
CPU limit: 48s
Limit duration: 60s
CPU used: 48s
Duration: 54.45s
Steps: 15
My app stopped crashing in iOS13 if I reduced the frequency for redrawing the map overlays.

WKWebview crash with Application received signal 11 error

I was using UIWebview before, and replace WKWbview on this version. Then I received a lot of error reports like this:
1 WebKit 0x18acddfe0 IPC::Connection::markCurrentlyDispatchedMessageAsInvalid() + 4
2 WebKit 0x18ad646e8 WebKit::NetworkProcessProxy::didReceiveAuthenticationChallenge(unsigned long long, unsigned long long, WebCore::AuthenticationChallenge const&, unsigned long long) + 108
3 WebKit 0x18ad668b0 voidIPC::handleMessage<Messages::NetworkProcessProxy::DidReceiveAuthenticationChallenge, WebKit::NetworkProcessProxy, void (WebKit::NetworkProcessProxy::*)(unsigned long long, unsigned long long, WebCore::AuthenticationChallenge const&, unsigned long long)>(IPC::Decoder&, WebKit::NetworkProcessProxy*, void (WebKit::NetworkProcessProxy::*)(unsigned long long, unsigned long long, WebCore::AuthenticationChallenge const&, unsigned long long)) + 108
4 WebKit 0x18acdd65c IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 164
5 WebKit 0x18acdfe54 IPC::Connection::dispatchOneMessage() + 232
6 JavaScriptCore 0x185ebff44WTF::RunLoop::performWork() + 172
7 JavaScriptCore 0x185ec021cWTF::RunLoop::performWork(void*) + 36
8 CoreFoundation 0x1815f542c___CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
9 CoreFoundation 0x1815f4d9c___CFRunLoopDoSources0 + 540
10 CoreFoundation 0x1815f29a8___CFRunLoopRun + 744
11 CoreFoundation 0x181522da4_CFRunLoopRunSpecific + 424
12 GraphicsServices 0x182f8d074_GSEventRunModal + 100
13 UIKit 0x1877ddc9c_UIApplicationMain + 208
14 iTouzi 0x1001792b8_main (main.m:17)
15 libdyld.dylib0x18053159c_start + 4
Now I don't know how to analyze this crash, does anyone know how to fix this crash?

iOS - Understanding my symbolicated crash report (help needed)

My app is rejected from the iOS store because the app is terminated after user log in. I'm not able to reproduce the problem (local devices, TestFlight), it looks like it only happens when the app is running in production.
I have symbolicated the crash report that I got from the App Store review team. I understand that a abort() is called ontThread 0. But I have a hard time understanding the crash report. I'm new to crash reports so I appreciate the help!
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Application Specific Information:
abort() called
Filtered syslog:
None found
Last Exception Backtrace:
0 CoreFoundation 0x192e2efe0 __exceptionPreprocess + 124
1 libobjc.A.dylib 0x191890538 objc_exception_throw + 56
2 CoreFoundation 0x192e35ef4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 140
3 CoreFoundation 0x192e32f54 ___forwarding___ + 916
4 CoreFoundation 0x192d2ed4c _CF_forwarding_prep_0 + 92
5 appname 0x1000c9ce4 -[PushPlugin setApplicationIconBadgeNumber:] (PushPlugin.m:573)
6 appname 0x10015d130 -[CDVCommandQueue execute:] + 504
7 appname 0x1000e6d98 -[CDVWKWebViewEngine handleCordovaMessage:] (CDVWKWebViewEngine.m:427)
8 appname 0x1000e6c40 -[CDVWKWebViewEngine userContentController:didReceiveScriptMessage:] (CDVWKWebViewEngine.m:413)
9 appname 0x1000e7b98 -[CDVWKWeakScriptMessageHandler userContentController:didReceiveScriptMessage:] (CDVWKWebViewEngine.m:601)
10 WebKit 0x19c729590 ScriptMessageHandlerDelegate::didPostMessage(WebKit::WebPageProxy&, WebKit::FrameInfoData const&, WebCore::SerializedScriptValue&) + 196
11 WebKit 0x19c6c8c48 WebKit::WebUserContentControllerProxy::didPostMessage(IPC::Connection&, unsigned long long, WebKit::FrameInfoData const&, unsigned long long, IPC::DataReference const&) + 176
12 WebKit 0x19c6cb0c0 void IPC::handleMessage<Messages::WebUserContentControllerProxy::DidPostMessage, WebKit::WebUserContentControllerProxy, void (WebKit::WebUserContentControllerProxy::*)(IPC::Connection&, unsigned long long, WebKit::FrameInfoData const&, unsigned long long, IPC::DataReference const&)>(IPC::Connection&, IPC::Decoder&, WebKit::WebUserContentControllerProxy*, void (WebKit::WebUserContentControllerProxy::*)(IPC::Connection&, unsigned long long, WebKit::FrameInfoData const&, unsigned long long, IPC::DataReference const&)) + 156
13 WebKit 0x19c4fbda4 IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 120
14 WebKit 0x19c6a4830 WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 32
15 WebKit 0x19c4c1c8c IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 164
16 WebKit 0x19c4c4484 IPC::Connection::dispatchOneMessage() + 232
17 JavaScriptCore 0x19769fff4 WTF::RunLoop::performWork() + 172
18 JavaScriptCore 0x1976a02cc WTF::RunLoop::performWork(void*) + 36
19 CoreFoundation 0x192ddd42c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
20 CoreFoundation 0x192ddcd9c __CFRunLoopDoSources0 + 540
21 CoreFoundation 0x192dda9a8 __CFRunLoopRun + 744
22 CoreFoundation 0x192d0ada4 CFRunLoopRunSpecific + 424
23 GraphicsServices 0x194774074 GSEventRunModal + 100
24 UIKit 0x198fbe058 UIApplicationMain + 208
25 appname 0x1000b2b78 main (main.m:32)
26 libdyld.dylib 0x191d1959c start + 4
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x0000000191e29014 __pthread_kill + 8
1 libsystem_pthread.dylib 0x0000000191ef3264 pthread_kill + 112
2 libsystem_c.dylib 0x0000000191d9d9c4 abort + 140
3 libc++abi.dylib 0x00000001918691b0 __cxa_bad_cast + 0
4 libc++abi.dylib 0x0000000191882c04 default_unexpected_handler() + 0
5 libobjc.A.dylib 0x0000000191890820 _objc_terminate() + 124
6 libc++abi.dylib 0x000000019187f5d4 std::__terminate(void (*)()) + 16
7 libc++abi.dylib 0x000000019187eef8 __cxxabiv1::exception_cleanup_func(_Unwind_Reason_Code, _Unwind_Exception*) + 0
8 libobjc.A.dylib 0x000000019189066c _objc_exception_destructor(void*) + 0
9 CoreFoundation 0x0000000192e35ef4 __methodDescriptionForSelector + 0
10 CoreFoundation 0x0000000192e32f54 ___forwarding___ + 916
11 CoreFoundation 0x0000000192d2ed4c _CF_forwarding_prep_0 + 92
12 appname 0x00000001000c9ce4 -[PushPlugin setApplicationIconBadgeNumber:] (PushPlugin.m:573)
13 appname 0x000000010015d130 -[CDVCommandQueue execute:] + 504
14 appname 0x00000001000e6d98 -[CDVWKWebViewEngine handleCordovaMessage:] (CDVWKWebViewEngine.m:427)
15 appname 0x00000001000e6c40 -[CDVWKWebViewEngine userContentController:didReceiveScriptMessage:] (CDVWKWebViewEngine.m:413)
16 appname 0x00000001000e7b98 -[CDVWKWeakScriptMessageHandler userContentController:didReceiveScriptMessage:] (CDVWKWebViewEngine.m:601)
17 WebKit 0x000000019c729590 ScriptMessageHandlerDelegate::didPostMessage(WebKit::WebPageProxy&, WebKit::FrameInfoData const&, WebCore::SerializedScriptValue&) + 196
18 WebKit 0x000000019c6c8c48 WebKit::WebUserContentControllerProxy::didPostMessage(IPC::Connection&, unsigned long long, WebKit::FrameInfoData const&, unsigned long long, IPC::DataReference const&) + 176
19 WebKit 0x000000019c6cb0c0 void IPC::handleMessage<Messages::WebUserContentControllerProxy::DidPostMessage, WebKit::WebUserContentControllerProxy, void (WebKit::WebUserContentControllerProxy::*)(IPC::Connection&, unsigned long long, WebKit::FrameInfoData const&, unsigned long long, IPC::DataReference const&)>(IPC::Connection&, IPC::Decoder&, WebKit::WebUserContentControllerProxy*, void (WebKit::WebUserContentControllerProxy::*)(IPC::Connection&, unsigned long long, WebKit::FrameInfoData const&, unsigned long long, IPC::DataReference const&)) + 156
20 WebKit 0x000000019c4fbda4 IPC::MessageReceiverMap::dispatchMessage(IPC::Connection&, IPC::Decoder&) + 120
21 WebKit 0x000000019c6a4830 WebKit::WebProcessProxy::didReceiveMessage(IPC::Connection&, IPC::Decoder&) + 32
22 WebKit 0x000000019c4c1c8c IPC::Connection::dispatchMessage(std::__1::unique_ptr<IPC::Decoder, std::__1::default_delete<IPC::Decoder> >) + 164
23 WebKit 0x000000019c4c4484 IPC::Connection::dispatchOneMessage() + 232
24 JavaScriptCore 0x000000019769fff4 WTF::RunLoop::performWork() + 172
25 JavaScriptCore 0x00000001976a02cc WTF::RunLoop::performWork(void*) + 36
26 CoreFoundation 0x0000000192ddd42c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
27 CoreFoundation 0x0000000192ddcd9c __CFRunLoopDoSources0 + 540
28 CoreFoundation 0x0000000192dda9a8 __CFRunLoopRun + 744
29 CoreFoundation 0x0000000192d0ada4 CFRunLoopRunSpecific + 424
30 GraphicsServices 0x0000000194774074 GSEventRunModal + 100
31 UIKit 0x0000000198fbe058 UIApplicationMain + 208
32 appname 0x00000001000b2b78 main (main.m:32)
33 libdyld.dylib 0x0000000191d1959c start + 4
...

iOS WKWebView JavaScriptCore WTFCrash

I added an webview instance on our app. But, sometimes crash occurs.
The crash called JavaScriptCore WTFCrash on call stack.
Crashed: com.apple.main-thread
0 JavaScriptCore 0x26062a22 WTFCrash + 53
1 JavaScriptCore 0x260629cd WTFPrintBacktrace + 128
2 WebKit 0x29a2ab95 WTF::HashTable<unsigned long long, WTF::KeyValuePair<unsigned long long, WTF::RefPtr<WebKit::CallbackBase> >, WTF::KeyValuePairKeyExtractor<WTF::KeyValuePair<unsigned long long, WTF::RefPtr<WebKit::CallbackBase> > >, WTF::IntHash<unsigned long long>, WTF::HashMap<unsigned long long, WTF::RefPtr<WebKit::CallbackBase>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<WTF::RefPtr<WebKit::CallbackBase> > >::KeyValuePairTraits, WTF::HashTraits<unsigned long long> >::begin() const + 30
3 WebKit 0x29a2ab4d WTF::Vector<WTF::RefPtr<WebKit::CallbackBase>, 0ul, WTF::CrashOnOverflow, 16ul>::reserveCapacity(unsigned long) + 24
4 WebKit 0x29a2aaa5 WTF::Vector<WTF::RefPtr<WebKit::CallbackBase>, 0ul, WTF::CrashOnOverflow, 16ul>::resize(unsigned long) + 44
5 WebKit 0x29a2a955 void WebKit::invalidateCallbackMap<WTF::RefPtr<WebKit::CallbackBase> >(WTF::HashMap<unsigned long long, WTF::RefPtr<WebKit::CallbackBase>, WTF::IntHash<unsigned long long>, WTF::HashTraits<unsigned long long>, WTF::HashTraits<WTF::RefPtr<WebKit::CallbackBase> > >&, WebKit::CallbackBase::Error) + 104
6 WebKit 0x29ad18b1 WebKit::WebPageProxy::resetState(WebKit::WebPageProxy::ResetStateReason) + 456
7 WebKit 0x29ad0897 WebKit::WebPageProxy::close() + 78
8 WebKit 0x29b8496d -[WKWebView dealloc] + 120
9 libobjc.A.dylib 0x223c13a9 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 388
10 CoreFoundation 0x22b1af89 _CFAutoreleasePoolPop + 16
11 CoreFoundation 0x22b2a251 -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 140
12 UIKit 0x2719f2ed -[UIViewController _setViewAppearState:isAnimating:] + 1088
13 UIKit 0x272152d1 -[UIViewController __viewDidDisappear:] + 172
14 UIKit 0x2719f6d3 -[UIViewController _endAppearanceTransition:] + 258
15 UIKit 0x2725b6fb -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:] + 886
16 UIKit 0x2733680f __49-[UINavigationController _startCustomTransition:]_block_invoke + 210
17 UIKit 0x272b4157 -[_UIViewControllerTransitionContext completeTransition:] + 90
18 UIKit 0x27418c7b __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke95 + 682
19 UIKit 0x271c1ba5 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 540
20 UIKit 0x271c1685 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 204
21 UIKit 0x271c157f -[UIViewAnimationState animationDidStop:finished:] + 78
22 QuartzCore 0x25221689 CA::Layer::run_animation_callbacks(void*) + 252
23 libdispatch.dylib 0x2277980f _dispatch_client_callout + 22
24 libdispatch.dylib 0x22787ba9 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1524
25 CoreFoundation 0x22bcdb6d __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 8
26 CoreFoundation 0x22bcc067 __CFRunLoopRun + 1574
27 CoreFoundation 0x22b1b229 CFRunLoopRunSpecific + 520
28 CoreFoundation 0x22b1b015 CFRunLoopRunInMode + 108
29 GraphicsServices 0x2410bac9 GSEventRunModal + 160
30 UIKit 0x271ef189 UIApplicationMain + 144
31 App 0x12d600 main (AppDelegate.swift:14)
32 libdispatch.dylib 0x227c3873 (Missing)
Does anybody has experienced similar this issue?
Your code has two issues:
- stringByEvaluatingJavaScriptFromString: returns an autoreleased NSString. You thus do not need to use stringWithFormat:.
- Your code does not have a valid format either.
pageText = [NSString stringWithFormat:#"%#", [webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"];
would correct the format error, however, because you are assigning pageText you run the risk of a crash later due to the autorelease.
The following is all that is necessary. NB: I am assuming that the Javascript is valid....
- (void)webViewDidFinishLoad:(UIWebView *)webView {
[pageText release], pageText = nil;
pageText = [[webView stringByEvaluatingJavaScriptFromString:#"document.body.innerHTML"] retain];
if (!pageText)
// innerHTML was empty
pageText = [[webView stringByEvaluatingJavaScriptFromString:#"document.body"] retain];
}
Note that the retain is added because you are assigning the pageText ivar instead of using a setter. Make sure you add [pageText release]; in your dealloc to prevent leaks. Be very careful when trying to access pageText elsewhere in your code as it could still be nil. Be defensive.

UIWebView iOS 5 : WebKit/JavaScriptCore crash

I'm trying to include a UIWebView based browser in my iPad application. It takes some time, which makes it hard to debug, but the app finally crashes, always on the same spot: the WebThread, on the JavaScriptCore WTF::StringImpl::hash() function. It produces EXC_BAD_ACCESS (SIGSEGV), KERN_INVALID_ADDRESS at 0x00000001.
The UIWebView is inside a view controller managed by another view controller (container) in a stack-like fashion. I'm only keeping four or less of those browsers in memory.
Anything about the crash log, or about what might be causing the crash?
This is the crash log of the web thread:
Thread 2 name: WebThread
Thread 2 Crashed:
0 JavaScriptCore 0x32a97d46 WTF::StringImpl::hash() const + 42
1 JavaScriptCore 0x32a97c6a WTF::HashTable<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityExtractor<WTF::StringImpl*>, WTF::StringHash, WTF::HashTraits<WTF::StringImpl*>, WTF::HashTraits<WTF::StringImpl*> >::lookupForWriting(WTF::StringImpl* const&) + 18
2 JavaScriptCore 0x32a9b028 std::pair<WTF::HashTableIterator<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityExtractor<WTF::StringImpl*>, WTF::StringHash, WTF::HashTraits<WTF::StringImpl*>, WTF::HashTraits<WTF::StringImpl*> >, bool> WTF::HashTable<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityExtractor<WTF::StringImpl*>, WTF::StringHash, WTF::HashTraits<WTF::StringImpl*>, WTF::HashTraits<WTF::StringImpl*> >::add<WTF::StringImpl*, WTF::StringImpl*, WTF::IdentityHashTranslator<WTF::StringImpl*, WTF::StringImpl*, WTF::StringHash> >(WTF::StringImpl* const&, WTF::StringImpl* const&) + 448
3 JavaScriptCore 0x32a9ae30 WTF::AtomicString::addSlowCase(WTF::StringImpl*) + 96
4 WebCore 0x31bade0c WebCore::AtomicHTMLToken::initializeAttributes(WTF::Vector<WebCore::HTMLToken::Attribute, 10ul> const&) + 232
5 WebCore 0x31b88076 WebCore::AtomicHTMLToken::AtomicHTMLToken(WebCore::HTMLToken&) + 302
6 WebCore 0x31b87eae WebCore::HTMLTreeBuilder::constructTreeFromToken(WebCore::HTMLToken&) + 14
7 WebCore 0x31b7d07e WebCore::HTMLDocumentParser::pumpTokenizer(WebCore::HTMLDocumentParser::SynchronousMode) + 150
8 WebCore 0x31bee29a WebCore::HTMLDocumentParser::resumeParsingAfterScriptExecution() + 50
9 WebCore 0x31bc87e6 WebCore::HTMLDocumentParser::notifyFinished(WebCore::CachedResource*) + 78
10 WebCore 0x31bc7448 WebCore::CachedResource::checkNotify() + 40
11 WebCore 0x31bc7308 WebCore::CachedScript::data(WTF::PassRefPtr<WebCore::SharedBuffer>, bool) + 84
12 WebCore 0x31bc7240 WebCore::CachedResourceRequest::didFinishLoading(WebCore::SubresourceLoader*, double) + 120
13 WebCore 0x31bc715e WebCore::SubresourceLoader::didFinishLoading(double) + 158
14 WebCore 0x31bc58c2 _ZN7WebCoreL16didFinishLoadingEP16_CFURLConnectionPKv + 46
15 CFNetwork 0x347737ee URLConnectionClient::_clientDidFinishLoading(URLConnectionClient::ClientConnectionEventQueue*) + 186
16 CFNetwork 0x3476849e URLConnectionClient::ClientConnectionEventQueue::processAllEventsAndConsumePayload(XConnectionEventInfo<XClientEvent, XClientEventParams>*, long) + 418
17 CFNetwork 0x3476819c URLConnectionClient::processEvents() + 100
18 CFNetwork 0x347680d2 MultiplexerSource::perform() + 150
19 CoreFoundation 0x313d2acc __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 8
20 CoreFoundation 0x313d2298 __CFRunLoopDoSources0 + 208
21 CoreFoundation 0x313d103e __CFRunLoopRun + 646
22 CoreFoundation 0x3135449e CFRunLoopRunSpecific + 294
23 CoreFoundation 0x31354366 CFRunLoopRunInMode + 98
24 WebCore 0x31b74c9c _ZL12RunWebThreadPv + 396
25 libsystem_c.dylib 0x33bca72e _pthread_start + 314
26 libsystem_c.dylib 0x33bca5e8 thread_start + 0
I had the same problem, spent the whole day... There were a LOT of different WebKit errors like these. Finally, I got it: this was a multi-threaded issue! I created the WebView from thread 1, then tried to modify its contents by means of JS functions in thread 2...
The simple performSelectorOnMainThread:withObject:waitUntilDone: fixed the problem!
Maybe this will help someone.
As the crash log suggests, it looks like it might be a JavaScript related problem. I assume the page you're loading has JavaScript on it? Out of interest, does the webpage run fine in Mobile Safari - is it just in a UIWebView that you have problems?
If you're unable to modify the JS, or web page seems to run fine on other mobile/desktop browsers or devices , I would suggest filing a bug with Apple along with the JavaScript used to reproduce the problem.

Resources