'MutationObserver not working if tab not focused

I am working on a chrome extension and i have a problem with MutationObserver, not sure if i am missing something or it's the normal behavior. The observer works when i am on the chrome tab which uses the mutation i receive messages when changes happens normal, but when i am not on tab, either i am on another tab or another window nothing happens until i comeback to the tab where i use mutation.

exemple let's say i use stackoverflow.com on a tab where i observe mutation all good i get the changes then i keep my tab open and i switch to another tab, the mutations stopped working like if the dom doesn't update when i am on another tab till i comeback.

window.onload = () => {


  console.log("init observer");

  let mutationBinaryObserver = new MutationObserver(function (mutations) {
    mutations.forEach(function (mutation) {
      if (
        mutation.target &&
        mutation.target.className &&
        typeof mutation.target.className === "string" &&
        mutation.target.className.indexOf("dialog-subtitle-badge") >= 0
      ) {
        getChatMessages();
      }
    });
  });
});

Thanks for your help and advice, my goal is to be using my computer and receiving updates from a tab on chrome even if i am not focusing it.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source