onFillInAddressWithAliasId: async()

in src/js/background/context-menu.js [211:270]


    onFillInAddressWithAliasId: async (info, tab) => {
      // Trim the context menu id to get the alias reference ID
      const selectedAliasId = info.menuItemId.replace(
        reuseAliasMenuIdPrefix,
        ""
      );
      // Get stored alias data
      const relayAddresses = await relayContextMenus.utils.getAliases();

      // Select the correct alias from the stored alias data
      const selectedAliasObject = relayAddresses.filter((alias) => {
        return alias.id === parseInt(selectedAliasId, 10);
      });

      const serverStoragePref = await getCachedServerStoragePref();

      const currentMaskType = selectedAliasObject[0].mask_type;
      const currentUsedOnValue = selectedAliasObject[0].used_on;

      const currentPage = new URL(tab.url);
      const currentPageHostName = currentPage.hostname;

      const used_on = relayContextMenus.utils.checkAndStoreUsedOnDomain(
        currentUsedOnValue,
        currentPageHostName
      );

      // Update server info with site usage
      const data = { used_on };
      const options = {
        auth: true,
        mask_type: currentMaskType,
      };

      // Save what site this mask was used on before filling input
      if (serverStoragePref) {
        await patchMaskInfo(
          "PATCH",
          parseInt(selectedAliasId, 10),
          data,
          options
        );
      } else {
        // Set the used_on field for the selected mask and the re-save the entire masks collection to local storage.
        selectedAliasObject[0].used_on = used_on;
        browser.storage.local.set({ relayAddresses: relayAddresses });
      }

      browser.tabs.sendMessage(
        tab.id,
        {
          type: "fillTargetWithRelayAddress",
          targetElementId: info.targetElementId,
          relayAddress: selectedAliasObject[0],
        },
        {
          frameId: info.frameId,
        }
      );
    },