How to enable context menu on devtools?

I use BrowserView as window devtoolswebcontents. It’s work fine. but there no context menu popup if i right click at like “

” dom element in elements tab. Can i get context menu like chrome devtools ?

1 Like

Test code

const {
    app,
    BrowserWindow,
    BrowserView
} = require('electron')

function createWindow() {
    const win = new BrowserWindow({
        width: 800,
        height: 600
    })
    win.loadFile('index.html')
    /** 
     * commend out this code , It will popup context menu
     * else devtools dont popup context menu
     * ========== start **/
    const serviceViewDevTools = new BrowserView();
    win.setBrowserView(serviceViewDevTools);
    serviceViewDevTools.setBounds({
        x: 400,
        y: 30,
        width: 400,
        height: 600
    });
    serviceViewDevTools.setAutoResize({
        width: true,
        height: true
    });
    // =============== end

    win.on("ready-to-show", () => {
        const contents = win.webContents
        // and commend out this line , It will popup context menu


        contents.setDevToolsWebContents(serviceViewDevTools.webContents);


        contents.openDevTools({
            mode: 'detach'
        })
    })
}

app.whenReady().then(() => {
    createWindow()
    app.on('activate', function () {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})

app.on('window-all-closed', function () {
    if (process.platform !== 'darwin') app.quit()
})