AliasIO / demodal

Demodal is a browser extension that automatically removes content blocking modals including paywalls, discount offers, promts to sign up or enter your email address and more.
https://www.demodal.com
MIT License
245 stars 22 forks source link

TypeError: node.dataset is undefined #17

Open nbfritch opened 1 year ago

nbfritch commented 1 year ago

I noticed this extension logs an error whenever an element containing only text is updated. This issue appears to be Firefox only. I observed this issue in v112.

The problem comes from this section of content.js line 154-156

mutations.every((mutation) =>
  Array.from(mutation.addedNodes).every((node) => node.dataset.demodal)
)

In firefox, when a node containing just text is updated, node.dataset is null, and the attempt to read .demodal causes a type error.

I think the above code could be changed as follows to filter out text-only mutations.

mutations.every((mutation) =>
  Array.from(mutation.addedNodes).every((node) => node.dataset == null || node.dataset.demodal)
)

Here is a minimal html file which triggers the issue once per second. npx http-server --port 8000 and navigate to http://localhost:8000/issue.html

<html>
<head>
  <script>
    document.addEventListener('DOMContentLoaded', () => {
      const content = document.getElementById("content");
      let count = 0;
      setInterval(() => {
        count++;
        content.innerText = `Some Content ${count}`;
      }, 1000);
    });
  </script>
</head>

<body>
  <div id="content">Some Content 0</div>
</body>
</html>