Back

Technologies:

javascriptjavascript
avatar
Tolerim
21 hours ago

What is the method for capturing console warnings and verbose messages?

While attempting to use the Chrome DevTools Protocol, I have incorporated both the Log and Runtime Domain. To enable these domains, I attach the debugger using the current tab ID and specify the version using '1.3'. However, I am encountering an issue where only some warning messages are displayed, and no verbose messages are being shown. Could you please assist me in identifying what I may be doing wrong?

// Set the current tab ID as tabId and attach the debugger to it
chrome.debugger.attach({ tabId }, '1.3', onDebuggerAttach.bind(null, tabId));

// Enable Log and Runtime domains
const onDebuggerAttach = async tabId => {
  await chrome.debugger.sendCommand({ tabId: tabId}, 'Log.enable');
  await chrome.debugger.sendCommand({ tabId: tabId}, 'Runtime.enable');
  chrome.debugger.onEvent.addListener(onDebugEvent);
};

// Retrieve console messages
const onDebugEvent = (debuggeeId = {}, message, params = {}) => {
  switch (message) {
    case 'Log.entryAdded':
    case 'Runtime.consoleAPICalled':
      handleConsoleMessage(params);
      break;
    default:
      break;
  }
};

Answers(1)
avatar
Tolerim
21 hours ago
Verified Answer
It seems like you are attaching the Debugger Protocol to the tab and enabling the Log and Runtime domains correctly. However, the reason you may not be getting all the verbose messages is that you might not have set the correct verbosity level for the Log.enable command. You can try passing an Object parameter with a level property to the Log.enable command, where the level value is 'verbose'. Here's an example:
await chrome.debugger.sendCommand({ tabId }, 'Log.enable', { level: 'verbose' });
This should give you more detailed log messages. Additionally, keep in mind that not all console messages may be captured depending on the context of the page you are debugging.
;