nect);
    reconnect();
    return function (message) {
      const messageId =
        Math.random().toString(36).substring(2) + Date.now().toString(36);
      return new Promise(resolve => {
        const payload = {
          message,
          messageId,
          shimId,
        };
        pendingMessages.set(messageId, resolve);
        channel.port1.postMessage(payload);
      });
    };
  })();

  const ramblerIdHelper = {
    getProfileInfo: (successCallback, _errorCallback) => {
      successCallback({});
    },
    openAuth: () => {
      sendMessageToAddon("optIn").then(function () {
        const openAuthArgs = arguments;
        window.ramblerIdHelper = undefined;
        const s = document.createElement("script");
        s.src = originalScript;
        document.head.appendChild(s);
        s.addEventListener("load", () => {
          const helper = window.ramblerIdHelper;
          for (const { fn, args } of callLog) {
            helper[fn].apply(helper, args);
          }
          helper.openAuth.apply(helper, openAuthArgs);
        });
      });
    },
  };

  const callLog = [];
  function addLoggedCall(fn) {
    ramblerIdHelper[fn] = () => {
      callLog.push({ fn, args: arguments });
    };
  }

  addLoggedCall("registerOnFrameCloseCallback");
  addLoggedCall("registerOnFrameRedirect");
  addLoggedCall("registerOnPossibleLoginCallback");
  addLoggedCall("registerOnPossibleLogoutCallback");
  addLoggedCall("registerOnPossibleOauthLoginCallback");

  window.ramblerIdHelper = ramblerIdHelper;
}
PK