tor-browser

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

microsoftVirtualAssistant.js (1477B)


      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 * Bug 1801277 - Shim Microsoft virtual assistant.
      9 *
     10 * The microsoft virtual assistant will break when accessing the indexedDB that
     11 * will throw a security error because the virtual assistant is under a
     12 * third-party tracking domain 'liveperson.net'. The shim replaces the indexedDB
     13 * with a fake interface that won't throw an error.
     14 */
     15 
     16 /* globals cloneInto */
     17 
     18 (function () {
     19  const win = window.wrappedJSObject;
     20 
     21  try {
     22    // We only replace the indexedDB when liveperson.net is loaded in a
     23    // third-party context. Note that this is not strictly correct because
     24    // this is a cross-origin check but not a third-party check.
     25    if (win.parent == win || win.location.origin == win.top.location.origin) {
     26      return;
     27    }
     28  } catch (e) {
     29    // If we get a security error when accessing the top-level origin, this
     30    // shows that the window is in a cross-origin context. In this case, we can
     31    // proceed to apply the shim.
     32    if (e.name != "SecurityError") {
     33      throw e;
     34    }
     35  }
     36 
     37  const emptyMsg = cloneInto({ message: "" }, window);
     38 
     39  const idb = {
     40    open: () => win.Promise.reject(emptyMsg),
     41  };
     42 
     43  Object.defineProperty(win, "indexedDB", {
     44    value: cloneInto(idb, window, { cloneFunctions: true }),
     45  });
     46 })();