tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

bug1901780-disable-legacy-mutation-events.js (1180B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 "use strict";
      6 
      7 /**
      8 * Bugs 1901780 - Disable legacy DOM Mutation Events to prevent performance issues.
      9 */
     10 
     11 /* globals exportFunction */
     12 
     13 console.info(
     14  "DOM Mutation Events have been disabled to prevent performance issues. See https://bugzilla.mozilla.org/show_bug.cgi?id=1901780 for details."
     15 );
     16 
     17 (function disableMutationEvents() {
     18  const whichEvents = [
     19    "domattrmodified",
     20    "domcharacterdatamodified",
     21    "domnodeinserted",
     22    "domnodeinsertedintodocument",
     23    "domnoderemoved",
     24    "domnoderemovedfromdocument",
     25    "domsubtreemodified",
     26  ];
     27 
     28  const { prototype } = window.wrappedJSObject.EventTarget;
     29  const { addEventListener } = prototype;
     30  Object.defineProperty(prototype, "addEventListener", {
     31    value: exportFunction(function (_type, b, c, d) {
     32      const type = _type?.toLowerCase();
     33      if (whichEvents.includes(type)) {
     34        return undefined;
     35      }
     36      return addEventListener.call(this, type, b, c, d);
     37    }, window),
     38  });
     39 })();