Search code examples
objective-cwebviewweb-inspectormacos-sierra

How to open Web Inspector on 10.12 Sierra?


This works in OS X:

WebPreferences *prefs = [webView preferences];
[prefs setDeveloperExtrasEnabled:YES];

WebInspector *inspector = [[WebInspector alloc] initWithWebView:webView];

But crashes in macOS:

-[WebInspector initWithWebView:]: unrecognized selector sent to instance 0xb1ab1ab1a

Is this Private API thrown out?

The code is taken from here.


Solution

  • They've renamed it: http://trac.webkit.org/changeset/189654

    TLDR:

    WebInspector *inspector = [WebInspector alloc];
    
    if ([inspector respondsToSelector:@selector(initWithWebView:)])
        [inspector initWithWebView:webView];
    else
        [inspector initWithInspectedWebView:webView];
    

    In case of future changes, just look at the WebKit source code.