@zoreal/oauth2-js 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -61,7 +61,7 @@ function unsafeClaims(idToken) {
61
61
 
62
62
  // src/wire.ts
63
63
  var WIRE_VERSION = 1;
64
- var SDK_VERSION = "0.1.21";
64
+ var SDK_VERSION = "0.1.22";
65
65
  var SDK_NAME = "@zoreal/oauth2-js";
66
66
  var DEFAULT_ISSUER = "https://id.zoreal.com";
67
67
  var POLL_INTERVAL_MS = 2e3;
@@ -863,6 +863,30 @@ function markReturnDone(requestId) {
863
863
  function isReturnDone(requestId) {
864
864
  return storage()?.getItem(DONE + requestId) !== null && storage()?.getItem(DONE + requestId) !== void 0;
865
865
  }
866
+ function visibleOrDone(requestId, signal) {
867
+ if (typeof document === "undefined" || document.visibilityState !== "hidden") {
868
+ return Promise.resolve(!isReturnDone(requestId));
869
+ }
870
+ return new Promise((resolve) => {
871
+ const finish = (value) => {
872
+ document.removeEventListener("visibilitychange", onVisible);
873
+ window.removeEventListener("storage", onStorage);
874
+ signal?.removeEventListener("abort", onAbort);
875
+ resolve(value);
876
+ };
877
+ const onVisible = () => {
878
+ if (document.visibilityState !== "hidden") finish(!isReturnDone(requestId));
879
+ };
880
+ const onStorage = () => {
881
+ if (isReturnDone(requestId)) finish(false);
882
+ };
883
+ const onAbort = () => finish(false);
884
+ document.addEventListener("visibilitychange", onVisible);
885
+ window.addEventListener("storage", onStorage);
886
+ signal?.addEventListener("abort", onAbort, { once: true });
887
+ if (isReturnDone(requestId)) finish(false);
888
+ });
889
+ }
866
890
  function returnToUrl() {
867
891
  if (typeof window === "undefined") return void 0;
868
892
  const { href } = window.location;
@@ -2174,7 +2198,7 @@ function startLogin(options) {
2174
2198
  controller.signal,
2175
2199
  { tolerateUnknownUntil: Date.now() + 15e3 }
2176
2200
  );
2177
- if (isReturnDone(requestId)) {
2201
+ if (!await visibleOrDone(requestId, controller.signal)) {
2178
2202
  throw new DOMException("aborted", "AbortError");
2179
2203
  }
2180
2204
  } else {