sindresorhus / electron-debug

Adds useful debug features to your Electron app
MIT License
749 stars 49 forks source link

Feature: Signal to Renderer to open Electron-Webview DevTools #37

Open ghost opened 8 years ago

ghost commented 8 years ago

A useful feature it would be if a signal is sent to the renderer process. Because then you can decide in Electron-Webview whether this also wants to open the DevTools.

sindresorhus commented 8 years ago

Why? Not sure I understand the use-case.

ghost commented 8 years ago

To Debug external Websources. In my case an Ionic WebApp

sindresorhus commented 8 years ago

But you can just use the shortcut or enable the option to open devtools automatically on startup. Maybe it would help if you provided an example usage.

ghost commented 8 years ago

The shortcut openes only the DevTools from electron.BrowserWindow. In the Renderer Process you can use the Electron Webview tag see api docs

An Example:

Main process

let win = new BrowserWindow({width: 800, height: 600, show: false});
win.on('closed', () => {
  win = null;
});

win.loadURL('file://index.html');
win.show();

Renderer Process: index.html

<html>
<body>
<webview id="view" src="web.whatsapp.com" />

<script>
const {ipcRenderer} = require('electron');

  $('#view')[0].addEventListener('dom-ready', function () {

    ipcRenderer.on('dev-tools-opened', (event, arg) => {
      $('#view')[0].openDevTools();
    });
  });
</script>

</body>
</html>

The dev-tools-opened Signal is fired from the openDevTools method

sindresorhus commented 8 years ago

Thanks for elaborating. Makes sense. I wonder though if there's any way we can handle that more automagically. Like maybe allow you to pass in the webview DOM element to electron-debug and have it handled for you? Ideas?

parro-it commented 7 years ago

Trying to solve https://github.com/parro-it/debug-menu/issues/6 I made some experiment using webContents.getFocusedWebContents(). It return webContents of webviews when they are focused.

I remember of this issue... I think it could be elegantly solved using getFocusedWebContents.

motin commented 6 years ago

@parro-it I followed your advice and implemented #64, thanks :)