Skip to content

Instantly share code, notes, and snippets.

@koenbok
Created March 13, 2015 10:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koenbok/b4ce1f6cd79228e96bf6 to your computer and use it in GitHub Desktop.
Save koenbok/b4ce1f6cd79228e96bf6 to your computer and use it in GitHub Desktop.
WKWebInspector.m
// https://github.com/WebKit/webkit/blob/master/Source/WebKit2/UIProcess/API/Cocoa/WKWebViewPrivate.h
@interface WKWebView (WKPrivate)
@property (nonatomic, setter=_setAllowsRemoteInspection:) BOOL _allowsRemoteInspection;
@property (copy, setter=_setCustomUserAgent:) NSString *_customUserAgent;
@end
@interface WKPreferences (WKPrivate)
@property (nonatomic, setter=_setCompositingBordersVisible:) BOOL _compositingBordersVisible;
@property (nonatomic, setter=_setCompositingRepaintCountersVisible:) BOOL _compositingRepaintCountersVisible;
@property (nonatomic, setter=_setTiledScrollingIndicatorVisible:) BOOL _tiledScrollingIndicatorVisible;
@property (nonatomic, setter=_setDeveloperExtrasEnabled:) BOOL _developerExtrasEnabled;
@end
// Web Inspector C API:
// https://github.com/WebKit/webkit/blob/master/Source/WebKit2/Shared/API/c/WKBase.h
typedef const struct OpaqueWKPage* WKPageRef;
typedef const struct OpaqueWKPageGroup* WKPageGroupRef;
typedef const struct OpaqueWKInspector* WKInspectorRef;
typedef const struct OpaqueWKPreferences* WKPreferencesRef;
// https://github.com/WebKit/webkit/blob/master/Source/WebKit2/UIProcess/API/C/WKInspector.h
WKInspectorRef WKPageGetInspector(WKPageRef pageRef);
void WKInspectorShow(WKInspectorRef inspector);
void WKInspectorShowConsole(WKInspectorRef inspector);
@interface WKView
@property (readonly) WKPageRef pageRef;
@end
@interface WKWebView (Extras)
@property (nonatomic, readonly) WKView *wkView;
@end
@implementation WKWebView (Extras)
- (WKView *)wkView
{
return [(NSValue *)[self valueForKey:@"_wkView"] pointerValue];
}
@end
- (void)showInspector:(BOOL)show
{
WKInspectorShowConsole(WKPageGetInspector(_webView2.wkView.pageRef));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment