So I'm working on a new project and we would like to create a desktop application for our users using Electron.
The problem is that I need custom contextmenus on the webview elements.
My progress so far that I can create contextmenus over the webview, but I cannot access the content under the click. :)
index.html:
<webview id="webViewDefault" class="active" src="http://example.com" minwidth="100%" minheight="100%" partition="somePartition" nodeintegration allowpopups></webview>
renderer.js
const electron = require('electron');
const Menu = electron.remote.Menu;
//Create contextmenu template
const WebViewMenu = Menu.buildFromTemplate([{
label: 'Button 1', click(){
console.log('Button 1 clicked');
}
},
{type: 'separator'}, {
label: 'Button 2', click(){
console.log('Button 2 clicked');
}
}
]);
//get webview
let defaultWebview = document.getElementById("webViewDefault");
//add event listner
defaultWebview.addEventListener("contextmenu", (event) => {
const t = event.srcElement.id.split('-');
WebViewMenu.popup(electron.remote.getCurrentWindow());
});
So how can I get for example a link's href attribute when a right click happens, so I can create a new tab for the user.
The tabs are working great, creating new webviews, selecting the active ones etc. I just need to get the urls, from the links ...: D