parro-it/debug-menu

Doesn't work inside <webview>

nfriend opened this issue ยท 4 comments

The context menu opens correctly when a right-clicked occurs inside a webview, but the inspector opens up to show the parent context, not the webview's context:

image

It would be more useful if the webview's inspector tools were automatically opened.

All that is required to fix this issue is to change this (lines 7-16):

function inpectMenuTemplate(pos) {
  return {
    label: 'Inspect element',
    click: () => {
      electron.remote
        .getCurrentWindow()
        .inspectElement(pos.x, pos.y);
    }
  };
}

to this:

function inpectMenuTemplate(pos) {
  return {
    label: 'Inspect element',
    click: () => {      
       webview.inspectElement(pos.x, pos.y);
    }
  };
}

Perhaps the target of the inspectElement call could be passed as an optional parameter during the install() function call?

Actually, if you use it as a electron-contextmenu-middleware the middleware method ctx argument has a elm property containing the element on which the click event occur.

We can use that to discover if the click happens inside a webview. Do you mind making a PR?

Sure, I can give it a shot. Thanks for the response!

I made a PR, hope you don't mind :)