@livx.cc/iab-escape 0.3.1 → 0.5.0

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/README.md CHANGED
@@ -108,6 +108,17 @@ myUi.onContinue(() => esc.dismiss());
108
108
 
109
109
  2026-11-16, organic links: iOS 26.7.3 with Facebook 587 and Instagram 455, and Android 16 with Facebook 587. Each combination passed 3/3 for calls on load and for late calls (SPA-style, 0.8 s after load).
110
110
 
111
+ ## Declined the prompt
112
+
113
+ "Continue here" navigates the webview to the destination (`continueUrl` / `data-continue-url`, default: the `url` / `data-url` target; with no url it only removes the overlay). The loader is kept (text `labels.continuing`, "Opening…") until the page unloads, so no bare host page shows in between. A custom UI calls `esc.continue()`.
114
+
115
+ `fallback` (`data-fallback`), default `'manual'`:
116
+
117
+ - `'auto'`: continues by itself when the page is still here `fallbackMs` (default 2500) after the fire. A native confirm may leave the page visible with timers running, so it only continues when `document.visibilityState` is `visible` and `document.hasFocus()` is true, re-checking every 150 ms up to `fallbackMaxMs` (15000). Device-unverified.
118
+ - `'parallel'`: fires the scheme and navigates to the destination `parallelDelayMs` (`data-parallel-delay-ms`, default 0) later, whatever the confirm answer. Risk: navigating may dismiss the app's confirm dialog before the user answers. Device-unverified.
119
+
120
+ No re-fire happens after either navigates.
121
+
111
122
  ## Limits
112
123
 
113
124
  - The schemes are undocumented by Meta and an app update can break them: keep a fallback link and monitor.
@@ -3,7 +3,7 @@ import { type Labels, type Theme } from './loader';
3
3
  import { type Rule } from './matrix';
4
4
  export type { Env, Labels, Rule, Theme };
5
5
  export interface State {
6
- phase: 'opening' | 'fallback' | 'dismissed' | 'reentry';
6
+ phase: 'opening' | 'fallback' | 'continuing' | 'dismissed' | 'reentry';
7
7
  url: string | null;
8
8
  }
9
9
  export interface AttemptInfo {
@@ -33,6 +33,16 @@ export declare class IabEscapeOptions {
33
33
  theme: Theme;
34
34
  /** Phase callback for a custom UI (also called when the built-in UI is on). */
35
35
  onState: ((state: State) => void) | null;
36
+ /** Where "Continue here" (and the auto fallback) navigates the webview. Default: `url`; none -> just dismiss. */
37
+ continueUrl: string | null;
38
+ /** 'auto': if the page did not go away after the fire, continue in the webview by itself. Device-unverified. */
39
+ fallback: 'manual' | 'auto' | 'parallel';
40
+ /** 'auto' only: wait this long after the fire before the first check. */
41
+ fallbackMs: number;
42
+ /** 'parallel' only: navigate to the destination this long after the scheme fires, whatever the confirm answer. */
43
+ parallelDelayMs: number;
44
+ /** 'auto' only: stop re-checking (every 500 ms while the page is unfocused or hidden) this long after the fire. */
45
+ fallbackMaxMs: number;
36
46
  /** Max automatic fires per page lifetime (the first fire + re-entry re-fires). */
37
47
  maxAutoFires: number;
38
48
  /** Injectable for tests. Default: globalThis.window. */
@@ -52,12 +62,16 @@ export declare class IabEscape {
52
62
  private wentAway;
53
63
  private locked;
54
64
  private dismissed;
65
+ private fallbackSeq;
66
+ private base;
55
67
  constructor(options?: Partial<IabEscapeOptions> | undefined);
56
68
  private get o();
57
69
  private get win();
58
70
  detect(): Env;
59
71
  getRule(): Rule | null;
60
72
  buildUrl(): string | null;
73
+ /** The page URL, captured before the first navigation (relative urls must not resolve against a scheme URL). */
74
+ private pageUrl;
61
75
  /** Resolves the target (relative `url` against the current location); the query is never re-serialized. */
62
76
  private target;
63
77
  /** Fire now. Call inside a user gesture when wired to a button. */
@@ -74,6 +88,14 @@ export declare class IabEscape {
74
88
  private state;
75
89
  /** Stops re-fires and removes the built-in loader. Wire a custom UI's "Continue here" to this. */
76
90
  dismiss(): void;
91
+ /** "Continue here": navigate the current webview to the destination, keeping the loader (no destination: just dismiss). */
92
+ continue(): void;
93
+ private continueTarget;
94
+ /**
95
+ * 'auto' fallback: if the page is still here after the fire, continue in the webview. A native confirm may leave
96
+ * the page 'visible' with timers running, so only continue when it is visible AND focused; else re-check.
97
+ */
98
+ private armAutoFallback;
77
99
  private fallback;
78
100
  private delay;
79
101
  /** One automatic fire: escape(), count it, start watching for re-entry, reveal the button soon after. */
package/dist/IabEscape.js CHANGED
@@ -12,7 +12,7 @@ function detectEnv(ua) {
12
12
  }
13
13
 
14
14
  // src/loader.ts
15
- var DEFAULT_LABELS = { opening: "Opening in your browser…", open: "Open in browser", stay: "Continue here" };
15
+ var DEFAULT_LABELS = { opening: "Opening in your browser…", open: "Open in browser", stay: "Continue here", continuing: "Opening…" };
16
16
  var VARS = {
17
17
  bg: "--iab-bg",
18
18
  fg: "--iab-fg",
@@ -42,6 +42,7 @@ class Loader {
42
42
  open;
43
43
  stay;
44
44
  spin;
45
+ msg;
45
46
  constructor(doc, labels, theme = {}, onStay) {
46
47
  this.doc = doc;
47
48
  this.labels = labels;
@@ -65,6 +66,14 @@ class Loader {
65
66
  this.open.hidden = false;
66
67
  this.stay.hidden = false;
67
68
  }
69
+ continuing() {
70
+ if (!this.root)
71
+ this.build();
72
+ this.spin.hidden = false;
73
+ this.open.hidden = true;
74
+ this.stay.hidden = true;
75
+ this.msg.textContent = this.labels.continuing;
76
+ }
68
77
  hide() {
69
78
  this.root?.remove();
70
79
  this.root = null;
@@ -86,7 +95,7 @@ class Loader {
86
95
  const style = this.doc.createElement("style");
87
96
  style.textContent = CSS;
88
97
  this.spin = this.el("div", "ie-spin");
89
- const msg = this.el("div", "ie-msg", this.labels.opening);
98
+ const msg = this.msg = this.el("div", "ie-msg", this.labels.opening);
90
99
  this.open = this.el("a", "ie-open", this.labels.open);
91
100
  this.stay = this.el("a", "ie-stay", this.labels.stay);
92
101
  this.stay.href = "#";
@@ -150,6 +159,11 @@ class IabEscapeOptions {
150
159
  labels = {};
151
160
  theme = {};
152
161
  onState = null;
162
+ continueUrl = null;
163
+ fallback = "manual";
164
+ fallbackMs = 2500;
165
+ parallelDelayMs = 0;
166
+ fallbackMaxMs = 15000;
153
167
  maxAutoFires = 3;
154
168
  window = null;
155
169
  }
@@ -164,6 +178,16 @@ function optionsFromDataset(d) {
164
178
  o.includeUnproven = true;
165
179
  if (d.url)
166
180
  o.url = d.url;
181
+ if (d.continueUrl)
182
+ o.continueUrl = d.continueUrl;
183
+ if (d.fallback === "auto" || d.fallback === "manual" || d.fallback === "parallel")
184
+ o.fallback = d.fallback;
185
+ const pd = d.parallelDelayMs?.trim();
186
+ if (pd && Number.isFinite(Number(pd)) && Number(pd) >= 0)
187
+ o.parallelDelayMs = Number(pd);
188
+ const fm = d.fallbackMs?.trim();
189
+ if (fm && Number.isFinite(Number(fm)) && Number(fm) >= 0)
190
+ o.fallbackMs = Number(fm);
167
191
  if (d.ui !== undefined)
168
192
  o.ui = d.ui !== "false";
169
193
  const theme = {};
@@ -182,6 +206,8 @@ function optionsFromDataset(d) {
182
206
  labels.open = d.labelOpen;
183
207
  if (d.labelStay)
184
208
  labels.stay = d.labelStay;
209
+ if (d.labelContinuing)
210
+ labels.continuing = d.labelContinuing;
185
211
  if (Object.keys(labels).length)
186
212
  o.labels = labels;
187
213
  return o;
@@ -189,19 +215,22 @@ function optionsFromDataset(d) {
189
215
  var WATCH_MS = 3000;
190
216
  var REVEAL_MS = 800;
191
217
  var REENTER_LOCK_MS = 1000;
218
+ var AUTO_RECHECK_MS = 150;
192
219
  var FIRED = "__iabEscapeFired";
193
220
  var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1] ?? "").has(key);
194
221
 
195
222
  class IabEscape {
196
223
  options;
197
- static version = "0.3.1";
198
- static buildTime = "2026-11-16T20:48:08.181Z";
224
+ static version = "0.5.0";
225
+ static buildTime = "2026-11-17T10:56:42.504Z";
199
226
  ldr = null;
200
227
  fires = 0;
201
228
  watching = false;
202
229
  wentAway = false;
203
230
  locked = false;
204
231
  dismissed = false;
232
+ fallbackSeq = 0;
233
+ base = "";
205
234
  constructor(options) {
206
235
  this.options = options;
207
236
  this.options = { ...new IabEscapeOptions, ...options };
@@ -225,8 +254,11 @@ class IabEscape {
225
254
  const target = rule && this.target();
226
255
  return rule && target ? rule.build(target) : null;
227
256
  }
257
+ pageUrl() {
258
+ return this.base ||= this.win.location.href;
259
+ }
228
260
  target() {
229
- const base = this.win.location.href;
261
+ const base = this.pageUrl();
230
262
  const input = this.o.url ?? base;
231
263
  let resolved;
232
264
  try {
@@ -297,7 +329,7 @@ class IabEscape {
297
329
  };
298
330
  }
299
331
  loader() {
300
- return this.ldr ??= new Loader(this.win.document, { ...DEFAULT_LABELS, ...this.o.labels }, this.o.theme, () => this.dismiss());
332
+ return this.ldr ??= new Loader(this.win.document, { ...DEFAULT_LABELS, ...this.o.labels }, this.o.theme, () => this.continue());
301
333
  }
302
334
  state(phase) {
303
335
  this.o.onState?.({ phase, url: this.buildUrl() });
@@ -307,6 +339,43 @@ class IabEscape {
307
339
  this.ldr?.hide();
308
340
  this.state("dismissed");
309
341
  }
342
+ continue() {
343
+ const to = this.continueTarget();
344
+ if (!to)
345
+ return this.dismiss();
346
+ this.dismissed = true;
347
+ if (this.o.ui)
348
+ this.loader().continuing();
349
+ this.state("continuing");
350
+ this.win.location.href = to;
351
+ }
352
+ continueTarget() {
353
+ const input = this.o.continueUrl ?? this.o.url;
354
+ if (!input)
355
+ return null;
356
+ try {
357
+ const u = new URL(input, this.pageUrl());
358
+ return /^https?:$/.test(u.protocol) ? /^https?:\/\//i.test(input) ? input : u.href : null;
359
+ } catch {
360
+ return null;
361
+ }
362
+ }
363
+ armAutoFallback() {
364
+ const { win } = this;
365
+ const doc = win.document;
366
+ const seq = ++this.fallbackSeq;
367
+ let waited = this.o.fallbackMs;
368
+ const check = () => {
369
+ if (seq !== this.fallbackSeq || this.dismissed || this.wentAway)
370
+ return;
371
+ if (doc.visibilityState === "visible" && (doc.hasFocus?.() ?? true))
372
+ return this.continue();
373
+ waited += AUTO_RECHECK_MS;
374
+ if (waited <= this.o.fallbackMaxMs)
375
+ win.setTimeout(check, AUTO_RECHECK_MS);
376
+ };
377
+ win.setTimeout(check, this.o.fallbackMs);
378
+ }
310
379
  fallback() {
311
380
  const url = this.buildUrl();
312
381
  if (url && this.o.ui)
@@ -327,6 +396,10 @@ class IabEscape {
327
396
  if (!this.dismissed)
328
397
  this.fallback();
329
398
  }, REVEAL_MS);
399
+ if (this.o.fallback === "auto")
400
+ this.armAutoFallback();
401
+ if (this.o.fallback === "parallel" && this.continueTarget())
402
+ this.win.setTimeout(() => this.continue(), this.o.parallelDelayMs);
330
403
  return true;
331
404
  }
332
405
  watchReentry() {
@@ -1,4 +1,4 @@
1
- (()=>{var{defineProperty:d,getOwnPropertyNames:A,getOwnPropertyDescriptor:L}=Object,O=Object.prototype.hasOwnProperty;function k(e){return this[e]}var _=(e)=>{var t=(u??=new WeakMap).get(e),i;if(t)return t;if(t=d({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of A(e))if(!O.call(t,n))d(t,n,{get:k.bind(e,n),enumerable:!(i=L(e,n))||i.enumerable})}return u.set(e,t),t},u;var R=(e)=>e;function I(e,t){this[e]=R.bind(null,t)}var S=(e,t)=>{for(var i in t)d(e,i,{get:t[i],enumerable:!0,configurable:!0,set:I.bind(t,i)})};var N={};S(N,{boot:()=>T});var M=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function h(e){let t=M.find(([,n])=>n.test(e))?.[0]??null,i=/iPhone|iPad|iPod/.test(e)?"ios":/Android/.test(e)?"android":null;return{app:t,os:i,inApp:t!==null}}var b={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here"},f={bg:"--iab-bg",fg:"--iab-fg",accent:"--iab-accent",accentFg:"--iab-accent-fg",radius:"--iab-radius",font:"--iab-font"};class c{doc;labels;theme;onStay;root=null;open;stay;spin;constructor(e,t,i={},n){this.doc=e;this.labels=t;this.theme=i;this.onStay=n}get visible(){return this.root!==null}show(){if(!this.root)this.build();this.spin.hidden=!1,this.open.hidden=!0,this.stay.hidden=!0}reveal(e){if(!this.root)this.build();this.open.href=e,this.open.hidden=!1,this.stay.hidden=!1}hide(){this.root?.remove(),this.root=null}el(e,t,i){let n=this.doc.createElement(e);if(n.className=t,i)n.textContent=i;return n}build(){let e=this.el("div","");e.id="iab-escape",e.setAttribute("role","status");let t=Object.keys(f).filter((s)=>this.theme[s]).map((s)=>`${f[s]}:${this.theme[s]}`).join(";");if(t)e.setAttribute("style",t);let i=this.doc.createElement("style");i.textContent=`
1
+ (()=>{var{defineProperty:u,getOwnPropertyNames:A,getOwnPropertyDescriptor:L}=Object,M=Object.prototype.hasOwnProperty;function O(e){return this[e]}var S=(e)=>{var t=(d??=new WeakMap).get(e),i;if(t)return t;if(t=u({},"__esModule",{value:!0}),e&&typeof e==="object"||typeof e==="function"){for(var n of A(e))if(!M.call(t,n))u(t,n,{get:O.bind(e,n),enumerable:!(i=L(e,n))||i.enumerable})}return d.set(e,t),t},d;var _=(e)=>e;function R(e,t){this[e]=_.bind(null,t)}var I=(e,t)=>{for(var i in t)u(e,i,{get:t[i],enumerable:!0,configurable:!0,set:R.bind(t,i)})};var D={};I(D,{boot:()=>x});var U=[["threads",/Barcelona/],["instagram",/Instagram/],["messenger",/FBAN\/MessengerForiOS|FB_IAB\/MESSENGER|Orca/],["facebook",/FBAN|FBAV|FB_IAB/]];function h(e){let t=U.find(([,n])=>n.test(e))?.[0]??null,i=/iPhone|iPad|iPod/.test(e)?"ios":/Android/.test(e)?"android":null;return{app:t,os:i,inApp:t!==null}}var b={opening:"Opening in your browser…",open:"Open in browser",stay:"Continue here",continuing:"Opening…"},f={bg:"--iab-bg",fg:"--iab-fg",accent:"--iab-accent",accentFg:"--iab-accent-fg",radius:"--iab-radius",font:"--iab-font"};class p{doc;labels;theme;onStay;root=null;open;stay;spin;msg;constructor(e,t,i={},n){this.doc=e;this.labels=t;this.theme=i;this.onStay=n}get visible(){return this.root!==null}show(){if(!this.root)this.build();this.spin.hidden=!1,this.open.hidden=!0,this.stay.hidden=!0}reveal(e){if(!this.root)this.build();this.open.href=e,this.open.hidden=!1,this.stay.hidden=!1}continuing(){if(!this.root)this.build();this.spin.hidden=!1,this.open.hidden=!0,this.stay.hidden=!0,this.msg.textContent=this.labels.continuing}hide(){this.root?.remove(),this.root=null}el(e,t,i){let n=this.doc.createElement(e);if(n.className=t,i)n.textContent=i;return n}build(){let e=this.el("div","");e.id="iab-escape",e.setAttribute("role","status");let t=Object.keys(f).filter((s)=>this.theme[s]).map((s)=>`${f[s]}:${this.theme[s]}`).join(";");if(t)e.setAttribute("style",t);let i=this.doc.createElement("style");i.textContent=`
2
2
  #iab-escape{position:fixed;inset:0;z-index:2147483647;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;
3
3
  padding:max(24px,env(safe-area-inset-top)) max(24px,env(safe-area-inset-right)) max(24px,env(safe-area-inset-bottom)) max(24px,env(safe-area-inset-left));
4
4
  background:var(--iab-bg,#fff);color:var(--iab-fg,#111);font:var(--iab-font,18px/1.35 -apple-system,system-ui,sans-serif);text-align:center}
@@ -8,4 +8,4 @@ background:var(--iab-bg,#fff);color:var(--iab-fg,#111);font:var(--iab-font,18px/
8
8
  #iab-escape [hidden]{display:none}
9
9
  @keyframes ie-r{to{transform:rotate(360deg)}}
10
10
  @media (prefers-color-scheme:dark){#iab-escape{background:var(--iab-bg,#111);color:var(--iab-fg,#f2f2f2)}}
11
- @media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let n=this.el("div","ie-msg",this.labels.opening);this.open=this.el("a","ie-open",this.labels.open),this.stay=this.el("a","ie-stay",this.labels.stay),this.stay.href="#",this.stay.addEventListener("click",(s)=>{s.preventDefault(),this.hide(),this.onStay?.()});for(let s of[i,this.spin,n,this.open,this.stay])e.appendChild(s);(this.doc.body??this.doc.documentElement).appendChild(e),this.root=e}}var m=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,g=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,v=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var y=[{app:"instagram",os:"ios",proven:!0,delayMs:0,build:g("instagram"),testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Instagram 455.0.0.35.67"}},{app:"facebook",os:"ios",proven:!0,delayMs:1500,build:m,testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Facebook 587.0.0.31.71"}},{app:"facebook",os:"android",proven:!0,delayMs:0,build:v,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:v,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:g("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:m,testedOn:null}];class w{url=null;userAgent=null;delayMs=null;includeUnproven=!1;markParam="iab_escaped";onAttempt=null;onResult=null;ui=!0;labels={};theme={};onState=null;maxAutoFires=3;window=null}function x(e){let t={},i=e.delayMs?.trim();if(i&&Number.isFinite(Number(i))&&Number(i)>=0)t.delayMs=Number(i);if(e.markParam!==void 0)t.markParam=e.markParam===""?null:e.markParam;if(e.includeUnproven!==void 0)t.includeUnproven=!0;if(e.url)t.url=e.url;if(e.ui!==void 0)t.ui=e.ui!=="false";let n={};if(e.accent)n.accent=e.accent;if(e.bg)n.bg=e.bg;if(e.fg)n.fg=e.fg;if(Object.keys(n).length)t.theme=n;let s={};if(e.labelOpening)s.opening=e.labelOpening;if(e.labelOpen)s.open=e.labelOpen;if(e.labelStay)s.stay=e.labelStay;if(Object.keys(s).length)t.labels=s;return t}var P=3000,F=800,U=1000,l="__iabEscapeFired",E=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class p{options;static version="0.3.1";static buildTime="2026-11-16T20:48:08.181Z";ldr=null;fires=0;watching=!1;wentAway=!1;locked=!1;dismissed=!1;constructor(e){this.options=e;this.options={...new w,...e}}get o(){return this.options}get win(){return this.o.window??globalThis.window}detect(){return h(this.o.userAgent??this.win.navigator.userAgent)}getRule(){let{app:e,os:t}=this.detect(),i=y.find((n)=>n.app===e&&n.os===t);return i&&(i.proven||this.o.includeUnproven)?i:null}buildUrl(){let e=this.getRule(),t=e&&this.target();return e&&t?e.build(t):null}target(){let e=this.win.location.href,t=this.o.url??e,i;try{i=new URL(t,e)}catch{return null}if(!/^https?:$/.test(i.protocol))return null;let n=/^https?:\/\//i.test(t)?t:i.href,s=n.indexOf("#"),a=s<0?n:n.slice(0,s),o=s<0?"":n.slice(s),r=this.o.markParam;if(r&&!E(a,r))a+=(a.includes("?")?/[?&]$/.test(a)?"":"&":"?")+r+"=1";return{href:a+o,noHash:a,protocol:i.protocol}}escape(){let e=this.getRule(),t=this.buildUrl();if(!e||!t)return!1;return this.o.onAttempt?.({rule:e,url:t}),this.win.location.href=t,this.watch({rule:e,url:t}),!0}auto(){let{win:e}=this,t=this.o.markParam,i=this.getRule();if(!i||e[l]||t&&E(e.location.href,t))return()=>{};e[l]=!0;let{document:n}=e;if(this.dismissed=!1,this.o.ui)this.loader().show();this.state("opening");let s=!1,a,o=()=>{if(s=!0,!this.fireNow())e[l]=!1},r=()=>{if(n.removeEventListener("DOMContentLoaded",r),this.delay(i)<=0)o();else a=e.setTimeout(o,this.delay(i))};if(n.readyState==="loading")n.addEventListener("DOMContentLoaded",r);else r();return()=>{if(s)return;if(n.removeEventListener("DOMContentLoaded",r),a!==void 0)e.clearTimeout(a);e[l]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new c(this.win.document,{...b,...this.o.labels},this.o.theme,()=>this.dismiss())}state(e){this.o.onState?.({phase:e,url:this.buildUrl()})}dismiss(){this.dismissed=!0,this.ldr?.hide(),this.state("dismissed")}fallback(){let e=this.buildUrl();if(e&&this.o.ui)this.loader().reveal(e);this.state("fallback")}delay(e){return this.o.delayMs??e.delayMs}fireNow(){if(!this.escape())return this.ldr?.hide(),!1;return this.fires++,this.watchReentry(),this.win.setTimeout(()=>{if(!this.dismissed)this.fallback()},F),!0}watchReentry(){if(this.watching)return;this.watching=!0;let{win:e}=this,t=e.document;e.addEventListener("pagehide",()=>{this.wentAway=!0}),t.addEventListener("visibilitychange",()=>{if(t.visibilityState==="hidden")this.wentAway=!0;else this.reenter()}),e.addEventListener("pageshow",(i)=>{if(i.persisted)this.wentAway=!0,this.reenter()})}reenter(){let{win:e}=this,t=this.getRule();if(!this.wentAway||this.locked||this.dismissed||!t)return;if(this.wentAway=!1,this.locked=!0,e.setTimeout(()=>{this.locked=!1},U),this.fires>=this.o.maxAutoFires)return this.fallback();if(this.o.ui)this.loader().show();if(this.state("reentry"),this.delay(t)<=0)this.fireNow();else e.setTimeout(()=>this.fireNow(),this.delay(t))}bindLink(e){let t=this.buildUrl();if(!t)return!1;return e.href=t,!0}watch(e){let{win:t}=this,i=!1,n=()=>{i=!0},s=()=>{if(t.document.visibilityState==="hidden")n()};t.addEventListener("pagehide",n),t.document.addEventListener("visibilitychange",s),t.setTimeout(()=>{t.removeEventListener("pagehide",n),t.document.removeEventListener("visibilitychange",s),this.o.onResult?.({...e,outcome:i?"left":"stayed-or-unknown"})},P)}}function T(e,t,i={}){t.IabEscape=p;let n=e?.currentScript;if(n?.hasAttribute("data-auto"))new p({...x(n.dataset),...i}).auto()}if(typeof document<"u")T(document,globalThis);})();
11
+ @media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let n=this.msg=this.el("div","ie-msg",this.labels.opening);this.open=this.el("a","ie-open",this.labels.open),this.stay=this.el("a","ie-stay",this.labels.stay),this.stay.href="#",this.stay.addEventListener("click",(s)=>{s.preventDefault(),this.hide(),this.onStay?.()});for(let s of[i,this.spin,n,this.open,this.stay])e.appendChild(s);(this.doc.body??this.doc.documentElement).appendChild(e),this.root=e}}var m=(e)=>e.protocol==="https:"?"x-safari-"+e.href:null,g=(e)=>(t)=>`${e}://extbrowser/?url=${encodeURIComponent(t.href)}`,v=(e)=>`intent://${e.noHash.replace(/^https?:\/\//i,"")}#Intent;scheme=${e.protocol.slice(0,-1)};end`;var y=[{app:"instagram",os:"ios",proven:!0,delayMs:0,build:g("instagram"),testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Instagram 455.0.0.35.67"}},{app:"facebook",os:"ios",proven:!0,delayMs:1500,build:m,testedOn:{date:"2026-11-16",os:"iOS 26.7.3",app:"Facebook 587.0.0.31.71"}},{app:"facebook",os:"android",proven:!0,delayMs:0,build:v,testedOn:{date:"2026-11-16",os:"Android 16",app:"Facebook 587.0.0.39.55"}},{app:"instagram",os:"android",proven:!1,delayMs:0,build:v,testedOn:null},{app:"threads",os:"ios",proven:!1,delayMs:0,build:g("barcelona"),testedOn:null},{app:"messenger",os:"ios",proven:!1,delayMs:1500,build:m,testedOn:null}];class k{url=null;userAgent=null;delayMs=null;includeUnproven=!1;markParam="iab_escaped";onAttempt=null;onResult=null;ui=!0;labels={};theme={};onState=null;continueUrl=null;fallback="manual";fallbackMs=2500;parallelDelayMs=0;fallbackMaxMs=15000;maxAutoFires=3;window=null}function T(e){let t={},i=e.delayMs?.trim();if(i&&Number.isFinite(Number(i))&&Number(i)>=0)t.delayMs=Number(i);if(e.markParam!==void 0)t.markParam=e.markParam===""?null:e.markParam;if(e.includeUnproven!==void 0)t.includeUnproven=!0;if(e.url)t.url=e.url;if(e.continueUrl)t.continueUrl=e.continueUrl;if(e.fallback==="auto"||e.fallback==="manual"||e.fallback==="parallel")t.fallback=e.fallback;let n=e.parallelDelayMs?.trim();if(n&&Number.isFinite(Number(n))&&Number(n)>=0)t.parallelDelayMs=Number(n);let s=e.fallbackMs?.trim();if(s&&Number.isFinite(Number(s))&&Number(s)>=0)t.fallbackMs=Number(s);if(e.ui!==void 0)t.ui=e.ui!=="false";let a={};if(e.accent)a.accent=e.accent;if(e.bg)a.bg=e.bg;if(e.fg)a.fg=e.fg;if(Object.keys(a).length)t.theme=a;let r={};if(e.labelOpening)r.opening=e.labelOpening;if(e.labelOpen)r.open=e.labelOpen;if(e.labelStay)r.stay=e.labelStay;if(e.labelContinuing)r.continuing=e.labelContinuing;if(Object.keys(r).length)t.labels=r;return t}var F=3000,N=800,P=1000,w=150,l="__iabEscapeFired",E=(e,t)=>new URLSearchParams(e.split("#")[0].split("?")[1]??"").has(t);class c{options;static version="0.5.0";static buildTime="2026-11-17T10:56:42.504Z";ldr=null;fires=0;watching=!1;wentAway=!1;locked=!1;dismissed=!1;fallbackSeq=0;base="";constructor(e){this.options=e;this.options={...new k,...e}}get o(){return this.options}get win(){return this.o.window??globalThis.window}detect(){return h(this.o.userAgent??this.win.navigator.userAgent)}getRule(){let{app:e,os:t}=this.detect(),i=y.find((n)=>n.app===e&&n.os===t);return i&&(i.proven||this.o.includeUnproven)?i:null}buildUrl(){let e=this.getRule(),t=e&&this.target();return e&&t?e.build(t):null}pageUrl(){return this.base||=this.win.location.href}target(){let e=this.pageUrl(),t=this.o.url??e,i;try{i=new URL(t,e)}catch{return null}if(!/^https?:$/.test(i.protocol))return null;let n=/^https?:\/\//i.test(t)?t:i.href,s=n.indexOf("#"),a=s<0?n:n.slice(0,s),r=s<0?"":n.slice(s),o=this.o.markParam;if(o&&!E(a,o))a+=(a.includes("?")?/[?&]$/.test(a)?"":"&":"?")+o+"=1";return{href:a+r,noHash:a,protocol:i.protocol}}escape(){let e=this.getRule(),t=this.buildUrl();if(!e||!t)return!1;return this.o.onAttempt?.({rule:e,url:t}),this.win.location.href=t,this.watch({rule:e,url:t}),!0}auto(){let{win:e}=this,t=this.o.markParam,i=this.getRule();if(!i||e[l]||t&&E(e.location.href,t))return()=>{};e[l]=!0;let{document:n}=e;if(this.dismissed=!1,this.o.ui)this.loader().show();this.state("opening");let s=!1,a,r=()=>{if(s=!0,!this.fireNow())e[l]=!1},o=()=>{if(n.removeEventListener("DOMContentLoaded",o),this.delay(i)<=0)r();else a=e.setTimeout(r,this.delay(i))};if(n.readyState==="loading")n.addEventListener("DOMContentLoaded",o);else o();return()=>{if(s)return;if(n.removeEventListener("DOMContentLoaded",o),a!==void 0)e.clearTimeout(a);e[l]=!1,this.ldr?.hide()}}loader(){return this.ldr??=new p(this.win.document,{...b,...this.o.labels},this.o.theme,()=>this.continue())}state(e){this.o.onState?.({phase:e,url:this.buildUrl()})}dismiss(){this.dismissed=!0,this.ldr?.hide(),this.state("dismissed")}continue(){let e=this.continueTarget();if(!e)return this.dismiss();if(this.dismissed=!0,this.o.ui)this.loader().continuing();this.state("continuing"),this.win.location.href=e}continueTarget(){let e=this.o.continueUrl??this.o.url;if(!e)return null;try{let t=new URL(e,this.pageUrl());return/^https?:$/.test(t.protocol)?/^https?:\/\//i.test(e)?e:t.href:null}catch{return null}}armAutoFallback(){let{win:e}=this,t=e.document,i=++this.fallbackSeq,n=this.o.fallbackMs,s=()=>{if(i!==this.fallbackSeq||this.dismissed||this.wentAway)return;if(t.visibilityState==="visible"&&(t.hasFocus?.()??!0))return this.continue();if(n+=w,n<=this.o.fallbackMaxMs)e.setTimeout(s,w)};e.setTimeout(s,this.o.fallbackMs)}fallback(){let e=this.buildUrl();if(e&&this.o.ui)this.loader().reveal(e);this.state("fallback")}delay(e){return this.o.delayMs??e.delayMs}fireNow(){if(!this.escape())return this.ldr?.hide(),!1;if(this.fires++,this.watchReentry(),this.win.setTimeout(()=>{if(!this.dismissed)this.fallback()},N),this.o.fallback==="auto")this.armAutoFallback();if(this.o.fallback==="parallel"&&this.continueTarget())this.win.setTimeout(()=>this.continue(),this.o.parallelDelayMs);return!0}watchReentry(){if(this.watching)return;this.watching=!0;let{win:e}=this,t=e.document;e.addEventListener("pagehide",()=>{this.wentAway=!0}),t.addEventListener("visibilitychange",()=>{if(t.visibilityState==="hidden")this.wentAway=!0;else this.reenter()}),e.addEventListener("pageshow",(i)=>{if(i.persisted)this.wentAway=!0,this.reenter()})}reenter(){let{win:e}=this,t=this.getRule();if(!this.wentAway||this.locked||this.dismissed||!t)return;if(this.wentAway=!1,this.locked=!0,e.setTimeout(()=>{this.locked=!1},P),this.fires>=this.o.maxAutoFires)return this.fallback();if(this.o.ui)this.loader().show();if(this.state("reentry"),this.delay(t)<=0)this.fireNow();else e.setTimeout(()=>this.fireNow(),this.delay(t))}bindLink(e){let t=this.buildUrl();if(!t)return!1;return e.href=t,!0}watch(e){let{win:t}=this,i=!1,n=()=>{i=!0},s=()=>{if(t.document.visibilityState==="hidden")n()};t.addEventListener("pagehide",n),t.document.addEventListener("visibilitychange",s),t.setTimeout(()=>{t.removeEventListener("pagehide",n),t.document.removeEventListener("visibilitychange",s),this.o.onResult?.({...e,outcome:i?"left":"stayed-or-unknown"})},F)}}function x(e,t,i={}){t.IabEscape=c;let n=e?.currentScript;if(n?.hasAttribute("data-auto"))new c({...T(n.dataset),...i}).auto()}if(typeof document<"u")x(document,globalThis);})();
package/dist/loader.d.ts CHANGED
@@ -2,6 +2,7 @@ export interface Labels {
2
2
  opening: string;
3
3
  open: string;
4
4
  stay: string;
5
+ continuing: string;
5
6
  }
6
7
  export declare const DEFAULT_LABELS: Labels;
7
8
  /** Styling API: the `#iab-escape` root, the classes below, and these CSS variables (all optional). */
@@ -23,12 +24,15 @@ export declare class Loader {
23
24
  private open;
24
25
  private stay;
25
26
  private spin;
27
+ private msg;
26
28
  constructor(doc: Document, labels: Labels, theme?: Theme, onStay?: (() => void) | undefined);
27
29
  get visible(): boolean;
28
30
  /** Spinner state (also resets a previously revealed button). */
29
31
  show(): void;
30
32
  /** Reveals the real `<a>` (so a tap works if the automatic fire was ignored) and the "stay" link. */
31
33
  reveal(href: string): void;
34
+ /** A continue navigation is under way: keep the overlay (no bare page in between), spinner + short text. */
35
+ continuing(): void;
32
36
  hide(): void;
33
37
  private el;
34
38
  private build;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livx.cc/iab-escape",
3
- "version": "0.3.1",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "description": "Move users from the Facebook / Instagram in-app browser to the device default browser, using only trigger methods proven on real devices.",
6
6
  "license": "MIT",