tags:

views:

523

answers:

2

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?

+4  A: 

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.

Peter Hosey
This works! Awesome! Side note: It sets the setting on the first load, which doesn't take effect until the app is restarted. Not sure how to get around this -- perhaps supply a default properties file...
loglibrarian: Set it earlier. If applicationWillFinishLaunching: isn't good enough, set it in your main() function.
Peter Hosey
Ok I know I'm pushing my luck here, but is there a way to programatically launch the web inspector? Perhaps a private api?
Private API is private because it will go away someday. (Or become public with no changes, if you're EXTREMELY lucky.) If you're feeling bold, class-dump WebKit and try using the WebInspectorWindowController. Be sure you guard everything so that you fail gracefully if it changes.
Peter Hosey
A: 

I tried doing so, but couldn't see WebInspector. Isn't it like ][NSUserDefaults standarduserDefaults] registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"WebKitDeveloperExtras"]]?

JongAm Park
Minus that ] at the front, yes.
Peter Hosey
Thanks. From webkit-dev mailing list I received another response.It should be done in its earliest moment like +initialize, or it can be issued on Unix prompt.defaults write com.yourcompany.programname WebKitDeveloperExtras -bool true
JongAm Park