0

I am writing a cdp backend for the chrome-devtool-frontend。 I can not see any output in chrome-devtool-frontend,when cdp backend emit "Runtime.consoleAPICalled" Event。

I make sure that I enable Runtime domain firstly.

"Runtime.executionContextCreated" event has been also emitted.

My cdp backend code:

const WebSocket = require('ws');
const executionContext = {
  id: 1,
  origin: 'http://my.local.xxxx.net:3000',
  name: 'top',
};
(async () => {
  const ws = new WebSocket(
    'wss://xxxxxxxxx',
    { perMessageDeflate: false }
  );
  await new Promise((resolve) => ws.once('open', resolve));
  console.log('connected!');

  ws.on('message', (msg) => {
    console.log(`Received: ${msg}`);
    const messageObj = JSON.parse(msg);
    const { id, method } = messageObj;

    if (method === 'Log.enable' && id) {
      ws.send(
        JSON.stringify({
          id,
          result: {},
        })
      );
    }

    if (method === 'Debugger.enable' && id) {
      ws.send(
        JSON.stringify({
          id,
          result: {
            debuggerId: '-252419454342719044.-5817058166285735043',
          },
        })
      );
    }

    if (method === 'Runtime.runIfWaitingForDebugger' && id) {
      ws.send(
        JSON.stringify({
          id,
          result: {},
        })
      );
    }
    if (method === 'Runtime.enable' && id) {
      ws.send(
        JSON.stringify({
          id,
          result: {},
        })
      );
      ws.send(
        JSON.stringify({
          method: 'Runtime.executionContextCreated',
          params: {
            context: executionContext,
          },
        })
      );

      setTimeout(() => {
        ws.send(
          JSON.stringify({
            method: 'Runtime.consoleAPICalled',
            params: {
              type: 'log',
              args: [
                {
                  type: 'string',
                  value: 'log here',
                },
              ],
              stackTrace: { callFrames: [] },
              executionContextId: 1,
              timestamp: new Date().getTime(),
            },
          })
        );
      }, 3000);
    }
  });
})();

Here is devtool's Protocal monitor screenshot enter image description here

enter image description here

enter image description here

sisiea
  • 61
  • 3
  • Try debugging the raw protocol listener of devtools by setting breakpoints in [devtools-on-devtools](https://stackoverflow.com/q/12291138), try finding where it deviates from a built-in console message. – wOxxOm Nov 18 '22 at 09:40

0 Answers0