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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With