sindresorhus/electron-context-menu

Does not work inside webview tags (electron-tabs)

patarapolw opened this issue · 2 comments

This project - https://github.com/brrd/electron-tabs

It appears that I can right click on the tabs area (which is outside webview), but not inside.

@patarapolw see this option: https://github.com/sindresorhus/electron-context-menu#window

You need to attach the context menu to each individual BrowserWindow or WebView.

Just leaving a comment here for the future this is totally possible, based on this comment: #37 (comment)

What you have to do is:

// Perform any actions needed on load
mainWindow.webContents.on('did-finish-load', () => {
    contextMenu({
        window: mainWindow,
        prepend: (defaultActions, params, mainWindow) => [
            // Can add custom right click actions here
        ], 
        showInspectElement: false
        },
    );
});

// Ref: https://github.com/sindresorhus/electron-context-menu/issues/37#issuecomment-628657983
app.on("web-contents-created", (e, contents) => { 
    if (contents.getType() == "webview") {
        // set context menu in webview contextMenu({ window: contents, });
        contextMenu({
            window: contents,
            prepend: (defaultActions, params, mainWindow) => [
                // Can add custom right click actions here
            ], 
            showInspectElement: false
            },
        );
    }
});

Just note you will have to implement inspect element if you want that working inside BrowserViews (since that only exists on BrowserWindows