Skip to content

Instantly share code, notes, and snippets.

@psineur
Created December 12, 2011 17:35
Show Gist options
  • Save psineur/1468281 to your computer and use it in GitHub Desktop.
Save psineur/1468281 to your computer and use it in GitHub Desktop.
UIWebView with js Debugger.
/** @class UIWebViewWithDebug UIWebView with additional js error on DEBUG.
* Tested on iPad with 4.3.5 & 5.0
*/
@interface UIWebViewWithDebug : UIWebView {} @end
#ifdef DEBUG
@class WebView;
@class WebScriptCallFrame;
@class WebFrame;
@interface WebView
- (void) setScriptDebugDelegate: (id) delegate;
@end
@interface WebScriptCallFrame
- (NSString *) functionName;
@end
#endif
@implementation UIWebViewWithDebug
#ifdef DEBUG
#warning Potential Reject
- (void) webView: (WebView *) webView
exceptionWasRaised: (WebScriptCallFrame *) frame
sourceId: (int) sid
line: (int) line
forWebFrame: (WebFrame *) webFrame
{
NSString *url = [self.request.URL absoluteString];
NSString *errorString = [NSString stringWithFormat: @"Exception at %@, in function: %@ line: %@", url , [frame functionName], [NSNumber numberWithInt: line]];
NSLog(errorString);
}
- (void) webView: (id) sender didClearWindowObject: (id) windowObject forFrame: (WebFrame*) frame
{
[sender setScriptDebugDelegate: self];
}
#endif
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment