0

I'd like to enable the "Custom formatters" setting in my Electron app's dev tools as described here: https://github.com/MarshallOfSound/electron-devtools-installer/issues/36#issuecomment-285956783

Enabling the setting manually is possible, but I'd like to do it automatically when dev tools is opened so that other developers don't have to remember to do it themselves.

Is it possible to automatically enable this setting with dev tools commands, via the Electron Debugger API?

I found that clicking the checkbox in dev tools goes through this code path in Chromium, but otherwise I wasn't able to figure out how I could do this programmatically using the debugger API.

I tried the following:

  mainWindow.webContents.once("dom-ready", async () => {
      const debug = mainWindow.webContents.debugger;
      try {
        debug.attach("1.1");
      } catch (err) {
        // debugger may already be attached
      }

      try {
        await debug.sendCommand("Runtime.enable");
        await debug.sendCommand("Runtime.setCustomObjectFormatterEnabled", { enabled: true });
      } finally {
        debug.detach();
      }
  });

But the setting doesn't appear to change.

jtbandes
  • 115,675
  • 35
  • 233
  • 266
  • CDP has [Runtime.setCustomObjectFormatterEnabled](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-setCustomObjectFormatterEnabled) so you can send it to your app via puppeteer. You'll probably need to launch the app with something like --remote-debugging-port=1234. This should be a one-time action, no need to bind it to opening of devtools. – wOxxOm Apr 14 '21 at 18:37
  • @wOxxOm Thanks, I don't know how I missed that. But I tried doing `debugger.sendCommand("Runtime.setCustomObjectFormatterEnabled", { enabled: true })`, and that didn't work. Have you used this before? – jtbandes Apr 14 '21 at 22:18
  • Try asking in their repo. Maybe they intentionally don't implement "experimental" commands. – wOxxOm Apr 15 '21 at 03:40
  • Filed https://github.com/electron/electron/issues/28668 – jtbandes Apr 15 '21 at 06:59

0 Answers0