Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doesn't show in webview #65

Closed
eyalap opened this issue Apr 21, 2019 · 2 comments
Closed

doesn't show in webview #65

eyalap opened this issue Apr 21, 2019 · 2 comments

Comments

@eyalap
Copy link

eyalap commented Apr 21, 2019

Using the latest version.
I am able to see the context menu in BrowserWindow however I dynamically render when needed using a react app and don't see the context menu.
I don't pass anything in the window option so according to the documentation it should be visible in the webview by default but isn't.

If I need to pass webview reference I'd like an example if possible, I don't understand how you expect to pass a reference to the webview which is in the renderer while the context menu is in the main process.
I have an ID for the element but can't access and get results from the DOM from the main process or pass the element itself using IPC since it doesn't work.

Thanks

@agata
Copy link

agata commented Apr 25, 2019

I found work around for this issue. Please use 'web-contents-created' event and window option.
(I am using Electron 5.0.0)

const electron = require('electron');
const {app, BrowserWindow, shell}  = electron;
const contextMenu = require('electron-context-menu');
...
app.on('web-contents-created', (e, contents) => {
  if (contents.getType() == 'webview') {
    // open link with external browser in webview
    contents.on('new-window', (e, url) => {
      e.preventDefault()
      shell.openExternal(url)
    })
    // set context menu in webview
    contextMenu({
      prepend: (defaultActions, params, browserWindow) => [{
        label: 'Rainbow',
        visible: params.mediaType === 'image'
      }],
      window: contents
    });
  }
});

@eyalap
Copy link
Author

eyalap commented Apr 28, 2019

Thanks @agata this workaround works !
@sindresorhus I'm closing this issue, but I do think it will work much better if it would be supported out of the box instead of a workaround like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants