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?
Apple recommends:
defaults write com.example.myApp WebKitDeveloperExtras -bool true
However, as far as I can tell, this may no longer work if you are running your application out of sandbox (which you may need to do during some stages of development). In case you run in to this problem, what worked for me is to set the value for the WebKitDeveloperExtras key in the NSGlobalDomain:
defaults write NSGlobalDomain WebKitDeveloperExtras -bool true
I tried doing so, but couldn't see the web inspector.
Isn't it the same as [[NSUserDefaults standarduserDefaults] registerDefaults:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:@"WebKitDeveloperExtras"]]
?
in my case (MacOSX 10.6.5) it didn't work.
I had to do the following in the windowDidLoad method of my webView WindowController:
/* Initialize webInspector. */ [[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"WebKitDeveloperExtras"]; [[NSUserDefaults standardUserDefaults] synchronize];
A REALLY easy way to do it... is in the terminal.... ⌘ ⬆ ☺
defaults write com.yourcompany.yourbundleid WebKitDeveloperExtras TRUE
(With OSX 10.8, use defaults write com.yourcompany.yourbundleid WebKitDeveloperExtras -bool true
instead).
NOTE: You MUST change com.yourcompany.yourbundleid
to YOUR specific "apps" (or whatever company's app bundle ID
it may be) before this will work!**
The nice thing about this... there is NO WAY to forget to take it out, turn it off, comment it out, etc... This is a LOCAL setting... and can be set for ANY webkit enabled app... If you don't see a Developer Menu, or whatnot.. fret not..
Right☝ (click) on the Webview and go to "Show Inspector".
Also, along the same lines, the following may do something as well.. but I havent tried it, so not sure..
defaults write com.yourcompany.yourbundleid IncludeDebugMenu 1
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.