javascriptmathjaxaddthisadblock

AdBlock blocks MathJax and AddThis


When AdBlock is enabled I got the following errors:

  1. AddThis: Uncaught Error: Must pass a string which will eval to a globally accessible object where callbacks will be stored

  2. MathJax: Uncaught EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self' * 'unsafe-inline'".

When AdBlock is disabled, everything works fine.

The problem appeared a couple of weeks ago.

Even when AdBlock is enabled everything works fine on sites that use MathJax: https://www.mathjax.org and https://math.stackexchange.com/

Possibly, something has changed and I need to change the code properly. How?

Thanks in advance.


Solution

  • Both errors refer to the same Content Security Policy (CSP) issue which is that unsafe eval() calls are disallowed. Ad blockers, such as AdBlock and Adblock Plus, have recently started using CSPs for cases where traditional techniques are insufficient (see Adblock Plus filter options).

    I was only able to reproduce it on emathhelp.net. There I was able to find the filter ||emathhelp.net^$csp=script-src 'self' * 'unsafe-inline' to be responsible for this which was added to the EasyList ad blocking list on May 15. In Adblock Plus you can find such filters by following these steps:

    1. Right-click anywhere on the page
    2. Select "Inspect" in the context menu
    3. Switch to the "Adblock Plus" tab in the window that opens
    4. Reload the page to populate the list in the tab
    5. Find the filter next to a request with the type "CSP"

    You can reach out to EasyList (GitHub, forum, website) to find out why they added a particular filter. They should also be able to help you restore any functionality that's broken.