Electron WebContents context-menu 1

Electron WebContents context-menu

var menu = new Menu();

//Basic Menu For Testing
menu.append(new MenuItem({ label: 'MenuItem1', click: function() { console.log("YES"); 
} }));
menu.append(new MenuItem({ type: 'separator' }));
menu.append(new MenuItem({ label: 'MenuItem2', type: 'checkbox', checked: true }));
app.on("web-contents-created", (...[/* event */, webContents]) => {

//Webview is being shown here as a window type
console.log(webContents.getType())
webContents.on("context-menu", (event, click) => {
  event.preventDefault();
  console.log(webContents.getType())
  menu.popup(webContents);
}, false);
});

Here is what the above code is Doing:
1. I’m creating a context menu
2. I’m appending some items to the context menu
3. I’m listening for the web-contents-created event
4. I’m listening for the context-menu event
5. I’m preventing the default context menu from showing
6. I’m showing the context menu I created

The problem is that the context menu is not showing up. I’ve tried to use the webContents.getType() method to see if the webContents is a window or a webview. It’s returning a window. I’ve also tried to use the webContents.isDestroyed() method to see if the webContents is destroyed. It’s returning false.

I’ve also tried to use the webContents.getURL() method to see if the webContents is the webview. It’s returning the URL of the webview.

I’ve also tried to use the webContents.getTitle() method to see if the webContents is the webview. It’s returning the title of the webview.

I’ve also tried to use the webContents.getFocusedWebContents() method to see if the webContents is the webview. It’s returning the webContents of the webview.

I’ve also tried to use the webContents.getOwnerBrowserWindow() method to see if the webContents is the webview. It’s returning the BrowserWindow of the webview.

I’ve also tried to use the webContents.getOwnerWebContents() method to see if the webContents is the webview. It’s returning the webContents of the webview.

I’ve also tried to use the webContents.getParentWebContents() method to see if the webContents is the webview. It’s returning the webContents of the webview.

I’ve also tried to use the webContents.getWebPreferences() method to see if the webContents is the webview. It’s returning the webPreferences of the webview.

I’ve also tried to use the webContents.getWebContents() method to see if the webContents is the webview. It’s returning the webContents of the webview.

I’ve also tried to use the webContents.getWebContentsId() method to see if the webContents is the webview. It’s returning the webContentsId of the webview.

I’ve also tried to use the webContents.getZoomFactor() method to see if the webContents is the webview. It’s returning the zoomFactor of the webview.

I’ve also tried to use the webContents.getZoomLevel() method to see if the webContents is the webview. It’s returning the zoomLevel of the webview.

I’ve also tried to use the webContents.getZoomLevelLimits() method to see if the webContents is the webview. It’s returning the zoomLevelLimits of the webview.

I’ve also tried to use the webContents.getZoomLevelRange() method to see if the webContents is the webview. It’s returning the zoomLevelRange of the webview.

I’ve also tried to use the webContents.getZoomLevels() method to see if the webContents is the webview. It’s returning the zoomLevels of the webview.

I’ve also tried to use the webContents.getZoomLevels() method to see if the webContents is the webview. It’s returning the zoomLevels of the webview.

I’ve also tried to use the webContents.getZoomLevels() method to see if the webContents is the webview. It’s returning the zoomLevels of the webview.

I’ve also tried

Similar Posts