Search code examples
cocoawebkit

Is there a way to use the WebKit web inspector from a Cocoa WebView object?


I would like to use the WebKit web inspector in a custom browser based on WebKit on OS X. Is it possible to use the web inspector on a webview object? If so, how?


Solution

  • Set WebKitDeveloperExtras to YES in your default user defaults when you send -[NSUserDefaults registerDefaults:]. This applies app-wide, of course.

    Remember that the user can change it to NO, so don't assume that it's YES—if it ever matters (e.g., when customizing the contextual menu), always check.

    Warning: This preference doesn't necessarily only enable the Element Inspector. Apple may extend it in the future to also control, say, a Debug menu in your menu bar. You may find this an unacceptable risk.