Search code examples
google-chromegoogle-chrome-extensionchrome-extension-manifest-v3

Preventing Chrome duplicate console entries


I am trying to create a YouTube extension and in the console I get duplicate entries. enter image description here

This makes debugging it more difficult as I have to constantly find in which entry all the console messages are going. I was wondering if there is any way to remove the entry when the extension is disabled or updated.


Solution

  • These are orphaned content script contexts created when reloading the extension and using executeScript to inject a new content script. Due to a bug in Chrome simply reloading the tab won't help.

    The only way to remove them:

    1. terminate the tab in Chrome's built-in Task Manager,
    2. then reload the tab.

    And a trick to simplify selecting the correct context:

    1. set a breakpoint in your content script, don't close devtools;
    2. reload the extension or perform any action for which your new content script has a listener where you added the breakpoint;
    3. now devtools should be paused on the breakpoint, just click the context selector and you'll see which one is current - it will be highlighted.