tor-browser

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

instagram.js (1541B)


      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 1804445 - instagram login broken with dFPI enabled
      9 *
     10 * Instagram login with Facebook account requires Facebook to have the storage
     11 * access under Instagram. This shim adds a request for storage access for
     12 * Facebook when the user tries to log in with a Facebook account.
     13 */
     14 
     15 console.warn(
     16  `When logging in, Firefox calls the Storage Access API on behalf of the site. See https://bugzilla.mozilla.org/show_bug.cgi?id=1804445 for details.`
     17 );
     18 
     19 // Third-party origin we need to request storage access for.
     20 const STORAGE_ACCESS_ORIGIN = "https://www.facebook.com";
     21 
     22 document.documentElement.addEventListener(
     23  "click",
     24  e => {
     25    const { target, isTrusted } = e;
     26    if (!isTrusted) {
     27      return;
     28    }
     29    const button = target.closest("button[type=button]");
     30    if (!button) {
     31      return;
     32    }
     33    const form = target.closest("#loginForm");
     34    if (!form) {
     35      return;
     36    }
     37 
     38    console.warn(
     39      "Calling the Storage Access API on behalf of " + STORAGE_ACCESS_ORIGIN
     40    );
     41    button.disabled = true;
     42    e.stopPropagation();
     43    e.preventDefault();
     44    document
     45      .requestStorageAccessForOrigin(STORAGE_ACCESS_ORIGIN)
     46      .then(() => {
     47        button.disabled = false;
     48        target.click();
     49      })
     50      .catch(() => {
     51        button.disabled = false;
     52      });
     53  },
     54  true
     55 );