Search code examples
google-chrome-devtoolschrome-devtools-protocol

Set Devtools Protocol event listener in DevTools-on-DevTools


In DevTools-on-DevTools it's possible to run DevTools protocol commands like this:

let Main = await import('./devtools-frontend/front_end/entrypoints/main/main.js');
await Main.MainImpl.sendOverProtocol('Network.enable');

(https://chromedevtools.github.io/devtools-protocol/#monitor)

In a Chrome extension it's possible to listen to the protocol events like this: chrome.debugger.onEvent.addListener(eventHandler);

Is there a similar way to attach a custom function to the protocol events in DevTools-on-DevTools?


Solution

  • Judging by the source code, there are onMessageSent and onMessageReceived hooks:

    (await import('./devtools-frontend/front_end/core/protocol_client/protocol_client.js'))
      .InspectorBackend.test.onMessageSent = (msg, target) => { /* do something */ }