Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

To get all the logs

chrome.debugger.getTargets((result) => console.log(result) ) 

Here we are adding a event listener

chrome.debugger.onEvent.addListener(onEvent);

chrome.tabs.query give you the current tab To enable the logs we have to sendCommand of Log.enable

chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) {
  // you can even attach tabId or targetId 
  chrome.debugger.attach(
    { targetId: "FC33D8084B688E98F5929B90326E3A27" },
    "1.3",
    () => {
      if (chrome.runtime.lastError) {
        console.log("runtime.lastError", chrome.runtime.lastError.message);
        return;
      }
      console.log("Debugger attached");
    }
  );
  chrome.debugger.sendCommand(
    { targetId: "FC33D8084B688E98F5929B90326E3A27" },
    "Log.enable",
    () => {
      if (chrome.runtime.lastError) {
        console.log("runtime.lastError", chrome.runtime.lastError.message);
        return;
      }
      console.log("Log enabled and result");
    }
  );
});

function onEvent(debuggeeId, message, params) {
 // Here you can get the logs
  console.log("params", params);
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda