0

I want to be able to log the tagname of the button which is clicked. If I try to log something in my content.js nothing gets displayed. The content.js is executed because I can see my log from background.js. Why logs from my content.js arent displayed?

background.js

chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
  if (request.type == "click_event") {
    console.log("click event captured in current webpage");
    //Call the callback passed to chrome.action.onClicked
  }
});

content.js

document.addEventListener("click", () => {
    console.log("some log which is not displayed")
    chrome.runtime.sendMessage({
      type: "click_event"
    });
  })
Max Hager
  • 536
  • 4
  • 13
  • 2
    Content script logs will appear in the console of the tab the script was injected in. – Titus Dec 11 '22 at 11:33

1 Answers1

3

As @Titus said, your Content script logs are displayed in the page you injected it in.

Browser extensions are made of different contexts:

  1. one for the background script
  2. one for the content script
  3. one for the popup

Let's say you want to see the logs for the background script, in this case you need to go in your browser extensions debug page and analyze the specific extension. It actually opens a Developer tools page dedicated to the extension background.

Let's say you want to see the logs for the content script, in this case you need to open the Developer tools window for the target page where you injected the script.

Let's say you want to see the logs for the extension popup, in this case you open the popup as you would do for any extension, right click it and open the Developer tools window for it.

Fabrizio
  • 233
  • 1
  • 10