How can i get the console log of the current website opened in a iframe or page using a chrome extensions

How can i get the console logs of the current website opened in a iframe … Read more How can i get the console log of the current website opened in a iframe or page using a chrome extensions

How can i get the console logs of the current website opened in a iframe or page using a chrome extensions, i am using chrome debugger protocol for that but i am able to figure the logs

chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
  console.log("tabs--->", tabs);
  console.log("tabs[0].id", tabs[0].id);

  chrome.debugger.attach({ tabId: tabs[0].id }, "1.1", () => {
    if (chrome.runtime.lastError) {
      console.log("runtime.lastError", chrome.runtime.lastError.message);
      return;
    }
    console.log("Debugger attached");
  });

  chrome.debugger.sendCommand({ tabId: tabs[0].id }, "Console.enable", () => {
    if (chrome.runtime.lastError) {
      console.log("runtime.lastError", chrome.runtime.lastError.message);
      return;
    }
    console.log("Log enabled and result");
  });

  const config = {
    source: "javascript",
    level: "log",
    text: "console.log('hello world')",
  };

  chrome.debugger.sendCommand({ tabId: tabs[0].id }, "Console.ConsoleMessage", config, () => {
    if (chrome.runtime.lastError) {
      console.log("runtime.lastError", chrome.runtime.lastError.message);
      return;
    }
    console.log("Log enabled and result");
  });
});

I have tried this above code it throws an error Console.ConsoleMessage not found

Source: JavaSript – Stack Overflow



Leave a Reply

Your email address will not be published. Required fields are marked *