Inspecting WebView not working since upgrade to Sierra

Hi,


I'm not sure if this is the right place for this question, but I'll try anyway.


We are using WebViews (and not WKWebViews) in our Mac application to display data and since a recent migration to Sierra, we are unable to inspect any WebView's content. In the past, we have been using the following to activate the inspector, but it does not seem to work anymore:


[[NSUserDefaults standardUserDefaults] setBool:TRUE forKey:@"WebKitDeveloperExtras"];


Reading the apps preferences with defaults read com.myCompany.myApp does confirm that the WebKitDeveloperExtras are enabled. A Develepment tools -> Inspect element menu does appear when right-clicking the WebView, but it's always disabled.


What am I missing here?


Thanks.

Answered by gmorin in 226681022

I finally found what the problem was.


For reasons I don't know, we manually created the menu item with a tag equal to 2024 and inserted this as the 'Inspect element' menu item. This mimics the 'Inspect element' item passed in the defaultMenuItems parameter of -webView:contextMenuItemsForElement:defaultMenuItems:.


NSMenuItem* inspectMenuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Inspect element" keyEquivalent:@""];
[inspectMenuItem setTag:2024];
[menu addItem:inspectMenuItem];


It worked fine until Sierra, but the 'Inspect element' item passed in Sierra now has a target and a selector, which wasn't the case before. I now use the item given to me by the framework and not a handmade copy.

Accepted Answer

I finally found what the problem was.


For reasons I don't know, we manually created the menu item with a tag equal to 2024 and inserted this as the 'Inspect element' menu item. This mimics the 'Inspect element' item passed in the defaultMenuItems parameter of -webView:contextMenuItemsForElement:defaultMenuItems:.


NSMenuItem* inspectMenuItem = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:@"Inspect element" keyEquivalent:@""];
[inspectMenuItem setTag:2024];
[menu addItem:inspectMenuItem];


It worked fine until Sierra, but the 'Inspect element' item passed in Sierra now has a target and a selector, which wasn't the case before. I now use the item given to me by the framework and not a handmade copy.

Inspecting WebView not working since upgrade to Sierra
 
 
Q