Strange WebKit error in UIWebView - can this be caught?

I am loading HTML / JS from a subdirectory of the document directory on an iPad in UIWebView. So far, everything is working fine. To debug the JS-Part, I added several alert(..); statements alert(..); to js file. In most cases, there are no problems with these warnings, but from time to time an error occurs in the console, and the application crashes:

WebKit discarded an uncaught exception in the webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame: delegate: <(null)> A route has already been registered for class 'Publication' and HTTP method 'ANY'

Question 1: What could be the problem? I mean ... this is a simple warning (); which seems to be causing this error in the console.

Question 2: can I catch these errors in my application? This way the application will not crash due to a simple JS () warning;

thanks

+4
source share
1 answer

You can create a JavaScriptAlert category for your UIWebView class. JavaScriptAlert + UIWebView.h

Cancel method:

 - (void)webView:(UIWebView *)sender runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(id)frame; 

This should handle warnings from JavaScript.

Then on the JavaScript side, if you are not working in debug mode, you can set the no-op function for a warning or console log. Sort of

 var noop = function () {}; console.log = noop; window.alert = noop; 
+1
source

Source: https://habr.com/ru/post/1382266/


All Articles