OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Can't get Chrome devtools frontend to display message in the console panel through Chrome Devtools Protocol

  • Thread starter Thread starter linjunchao
  • Start date Start date
L

linjunchao

Guest
I cloned the Chrome devtools frontend source code and ran npx http-server .. Then I visited http://127.0.0.1:8080/front_end/devtools_app.html?ws=localhost:8899, which connects to my backend WebSocket server (localhost:8899). The server listens for messages from the frontend and responds using the Chrome DevTools Protocol. However, the console panel displays nothing. How can I activate the console so it displays messages?

This is my backend code:

Code:
const { WebSocketServer } = require('ws');
const wss = new WebSocketServer({ port: 8899 });
wss.on('connection', function connection(ws) {
  ws.on('message', function message(data) {
    console.log('received: %s', data);
    const message = JSON.parse(data);
    if (message.method === 'Runtime.enable') {
      ws.send(
        JSON.stringify({
          method: 'Runtime.consoleAPICalled',
          params: {
           args: [
            {
              type: 'string',
              value: 'MESSAGE THAT I WANT TO SHOW IN THE CONSOLE PANEL'
            }
           ],
           executionContextId: 27,
           timestamp: new Date().getTime(),
          },
        })
      );
    }
  });
});

<p>I cloned the Chrome devtools frontend source code and ran <code>npx http-server .</code>. Then I visited <code>http://127.0.0.1:8080/front_end/devtools_app.html?ws=localhost:8899</code>, which connects to my backend WebSocket server (<code>localhost:8899</code>). The server listens for messages from the frontend and responds using the <strong>Chrome DevTools Protocol</strong>. However, the console panel displays nothing. How can I activate the console so it displays messages?</p>
<p>This is my backend code:</p>
<pre class="lang-js prettyprint-override"><code>const { WebSocketServer } = require('ws');
const wss = new WebSocketServer({ port: 8899 });
wss.on('connection', function connection(ws) {
ws.on('message', function message(data) {
console.log('received: %s', data);
const message = JSON.parse(data);
if (message.method === 'Runtime.enable') {
ws.send(
JSON.stringify({
method: 'Runtime.consoleAPICalled',
params: {
args: [
{
type: 'string',
value: 'MESSAGE THAT I WANT TO SHOW IN THE CONSOLE PANEL'
}
],
executionContextId: 27,
timestamp: new Date().getTime(),
},
})
);
}
});
});
</code></pre>
 
Top