@livx.cc/iab-escape 0.3.0 → 0.3.1

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
@@ -1,36 +1,22 @@
1
1
  # @livx.cc/iab-escape
2
2
 
3
- Move a user from the Facebook / Instagram in-app browser (IAB) to the device default browser. Zero dependencies, no logging, no analytics. Triggers mirror the ones tested on real devices.
3
+ Opens your page in the user's real browser when it was opened inside the Facebook or Instagram in-app browser.
4
4
 
5
- ## Proven matrix
5
+ In-app browsers lose logins, cookies, payments, app-store and passkey flows. This reopens the same URL in Safari or the default browser. Zero dependencies, no logging, no analytics.
6
6
 
7
- Tested 2026-11-16, organic links (not paid ads). The app always shows its own confirm dialog: the user taps once.
8
-
9
- | App | OS | Scheme | Trigger tested | Result |
10
- |---|---|---|---|---|
11
- | Instagram 455.0.0.35.67 | iOS 26.7.3 | `instagram://extbrowser/?url=<enc>` | `<a>`, tap, and sync `location.href` while parsing (3/3 each) | Safari |
12
- | Facebook 587.0.0.31.71 | iOS 26.7.3 | `x-safari-https://host/path` | `<a>`/tap (3/3); `setTimeout(1500)` from an inline script (3/3); sync firing while parsing fails | Safari |
13
- | Facebook 587.0.0.39.55 | Android 16 | `intent://host/path#Intent;scheme=https;end` | `<a>`/tap: 1 run each; sync `location.href` while parsing: 3/3 | Chrome (default browser) |
14
-
15
- Unproven, returned only with `includeUnproven: true`: Instagram Android (intent), Threads iOS (`barcelona://extbrowser`), Messenger iOS (`x-safari-https`).
16
-
17
- ## Usage
18
-
19
- It reopens the **same URL** in the default browser. In a normal browser it does nothing.
20
-
21
- Script tag, placed early in the page (no code):
7
+ ## Quick start
22
8
 
23
9
  ```html
24
- <script src="iab-escape.min.js" data-auto></script>
10
+ <script src="https://cdn.jsdelivr.net/npm/@livx.cc/iab-escape@0.3/dist/iab-escape.min.js" data-auto></script>
25
11
  ```
26
12
 
27
- `auto()` shows, **by default** (script tag and npm API alike), a full-screen loader ("Opening in your browser…"), then an "Open in browser" button (a real link, works if the automatic fire was ignored) and a small "Continue here". Turn it off with `data-ui="false"` or `ui: false`. No loader when the app is not matched.
28
-
29
- Re-entry: if the page comes back after it left (persisted `pageshow`, or hidden then visible), it fires again once per return, at most `maxAutoFires` (default 3) per page lifetime. If the user cancelled the app's dialog (the page never went away), it does not re-fire; the button stays. "Continue here" stops re-fires.
13
+ Place it early in the page. In any other browser it does nothing: no UI, no navigation.
30
14
 
31
- Optional attributes: `data-ui`, `data-accent`, `data-bg`, `data-fg`, `data-label-opening`, `data-label-open`, `data-label-stay`, `data-delay-ms`, `data-mark-param` (empty = off), `data-include-unproven`, `data-url`.
15
+ ## Install
32
16
 
33
- npm:
17
+ ```sh
18
+ npm i @livx.cc/iab-escape # or: bun add @livx.cc/iab-escape
19
+ ```
34
20
 
35
21
  ```ts
36
22
  import { IabEscape } from '@livx.cc/iab-escape';
@@ -40,18 +26,60 @@ esc.auto(); // once per page load
40
26
  esc.bindLink(document.querySelector('a#open')!); // fallback button/link
41
27
  ```
42
28
 
43
- The script build also exposes the global `IabEscape` class (`IabEscape.version`, `IabEscape.buildTime`). The ESM import has no side effects.
29
+ The ESM import has no side effects. The script build also exposes the global `IabEscape` class (`IabEscape.version`, `IabEscape.buildTime`).
30
+
31
+ ## What the user sees
32
+
33
+ 1. A full-screen loader ("Opening in your browser...").
34
+ 2. The app's own confirm dialog. It cannot be skipped: the user taps once.
35
+ 3. The page reopens in the browser.
36
+
37
+ If the user cancels, they stay on the page with an "Open in browser" button (a real link) and a small "Continue here". If the page comes back after it left (persisted `pageshow`, or hidden then visible), it fires again, at most `maxAutoFires` (default 3) per page lifetime. A cancelled dialog does not re-fire. "Continue here" stops re-fires.
38
+
39
+ ## Supported
40
+
41
+ | App | OS | Opens in |
42
+ |---|---|---|
43
+ | Facebook | iOS | Safari |
44
+ | Instagram | iOS | Safari |
45
+ | Facebook | Android | Default browser |
46
+
47
+ Experimental, returned only with `includeUnproven`: Instagram Android, Threads iOS, Messenger iOS.
44
48
 
45
- **Call `auto()` from an inline script**, as the probes did. If the document is still `loading`, it waits for `DOMContentLoaded` (never `load`), because navigating mid-parse leaves a half-loaded page when the user comes back (seen on Android Facebook). Then delay 0 fires synchronously and a longer delay starts a timer. If the document is already `interactive`/`complete`, the delay counts from the `auto()` call. So it fires at `DOMContentLoaded` at the earliest; on iOS Facebook the 1.5 s counts from then or from the call, whichever is later.
49
+ ## Options and API
46
50
 
47
- - `detect()` returns `{ app, os, inApp }`; `getRule()` the matrix row (with `testedOn`); `buildUrl()` the scheme URL or null.
48
- - `escape()` fires now (call inside a tap for buttons). `auto()` returns a cancel function; cancelling before the fire re-arms the once-per-page guard (flag on the window, shared by all instances).
49
- - `auto()` does nothing when the current page URL already carries the mark param (loop guard); `escape()` still works.
50
- - Options: `url` (relative resolves against the page), `userAgent`, `delayMs`, `includeUnproven`, `markParam` (default `iab_escaped`, appended raw as `=1` only if absent, query otherwise byte-identical; `null` disables), `ui`, `labels`, `theme`, `maxAutoFires`, `onState`, `onAttempt`, `onResult`, `window`. `dismiss()` stops re-fires and removes the loader.
51
+ Script-tag attributes map to the JS options.
52
+
53
+ | Option | Attribute | Default | Purpose |
54
+ |---|---|---|---|
55
+ | `url` | `data-url` | current page | Target URL (relative resolves against the page) |
56
+ | `userAgent` | | `navigator.userAgent` | Override detection input |
57
+ | `delayMs` | `data-delay-ms` | per app | Delay before firing |
58
+ | `includeUnproven` | `data-include-unproven` | `false` | Enable experimental rules |
59
+ | `markParam` | `data-mark-param` | `iab_escaped` | Loop-guard query param; `null` / empty disables |
60
+ | `ui` | `data-ui` | `true` | Built-in loader and buttons |
61
+ | `labels` | `data-label-opening`, `-open`, `-stay` | English | UI text |
62
+ | `theme` | `data-accent`, `data-bg`, `data-fg` | built-in | Colors |
63
+ | `maxAutoFires` | | `3` | Max automatic fires per page lifetime |
64
+ | `onState` | | | Phase callback for your own UI |
65
+ | `onAttempt`, `onResult` | | | Fire / outcome callbacks |
66
+ | `window` | | `window` | Window to use (tests, iframes) |
67
+
68
+ Methods:
69
+
70
+ - `detect()`: returns `{ app, os, inApp }`.
71
+ - `getRule()`: the matching rule (with `testedOn`).
72
+ - `buildUrl()`: the scheme URL, or null.
73
+ - `auto()`: fires automatically; returns a cancel function. Does nothing when the page URL already has the mark param.
74
+ - `escape()`: fires now (call inside a tap for buttons).
75
+ - `bindLink(el)`: makes a link or button open the browser.
76
+ - `dismiss()`: stops re-fires and removes the loader.
77
+
78
+ Cancelling before the fire re-arms the once-per-page guard (a flag on the window, shared by all instances).
51
79
 
52
80
  ## Customize
53
81
 
54
- Styling API: `#iab-escape` and the classes `ie-msg`, `ie-spin`, `ie-open`, `ie-stay`. CSS variables (all optional): `--iab-bg`, `--iab-fg`, `--iab-accent`, `--iab-accent-fg`, `--iab-radius`, `--iab-font`.
82
+ Styling hooks: `#iab-escape` and the classes `ie-msg`, `ie-spin`, `ie-open`, `ie-stay`. CSS variables (all optional): `--iab-bg`, `--iab-fg`, `--iab-accent`, `--iab-accent-fg`, `--iab-radius`, `--iab-font`.
55
83
 
56
84
  ```css
57
85
  #iab-escape { --iab-accent: #e33; --iab-radius: 4px; }
@@ -69,20 +97,38 @@ esc.auto();
69
97
  myUi.onContinue(() => esc.dismiss());
70
98
  ```
71
99
 
100
+ ## How it works
101
+
102
+ - Each app has its own hand-off: Instagram iOS `instagram://extbrowser/?url=<enc>`, Facebook iOS `x-safari-https://host/path` (fired after a 1.5 s delay), Facebook Android `intent://host/path#Intent;scheme=https;end`.
103
+ - If the document is still loading, `auto()` waits for `DOMContentLoaded` (never `load`), because navigating mid-parse leaves a half-loaded page on return. If it is already `interactive`/`complete`, the delay counts from the call.
104
+ - It adds `iab_escaped=1` to the target as a loop guard; the rest of the query stays byte-identical.
105
+ - It never uses meta refresh: that loops on Android when the user cancels.
106
+
107
+ ## Tested on
108
+
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
+
72
111
  ## Limits
73
112
 
74
113
  - The schemes are undocumented by Meta and an app update can break them: keep a fallback link and monitor.
75
- - `data-auto` uses the same `auto()` path (unit-tested); the device runs used the inline `auto()` call.
114
+ - A late `auto()` call (0.8 s after load) was tested 3/3 on Facebook iOS, Instagram iOS and Facebook Android. Only slow or heavy pages remain untested.
76
115
  - A bare `?iab_escaped` (no value) counts as "mark present": the URL is left untouched and `auto()` is skipped.
77
116
  - Paid-ad clicks are untested (organic links only).
78
117
  - A production domain with universal links may open the native app instead of the browser.
79
118
  - Instagram passes no `fbclid` from a DM; Facebook rewrites the `fbclid` at the hand-off.
80
- - Slow or heavy pages, and a late `auto()` call (after `load`, e.g. an SPA mount), are untested on devices.
81
119
  - Matched by the rules but untested: Instagram on iPad, Facebook Lite, `http` targets on Android (`scheme=http`) and Instagram. On iOS Facebook `http` targets return null.
82
- - Never uses meta refresh: it loops on Android when the user cancels.
83
120
  - `onResult` watches `visibilitychange`/`pagehide` for 3 s. Meta webviews do not fire these reliably, so `stayed-or-unknown` is not proof of failure.
84
121
  - The app's confirm dialog cannot be skipped.
85
122
 
86
- ## Dev
123
+ ## Development
124
+
125
+ ```sh
126
+ bun test
127
+ bun run build
128
+ ```
129
+
130
+ Open `demo/index.html` via a static server after building.
131
+
132
+ ## License
87
133
 
88
- `bun test`, `bun run build`. Open `demo/index.html` via a static server after building.
134
+ MIT
package/dist/IabEscape.js CHANGED
@@ -194,8 +194,8 @@ var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1]
194
194
 
195
195
  class IabEscape {
196
196
  options;
197
- static version = "0.3.0";
198
- static buildTime = "2026-11-16T20:42:33.752Z";
197
+ static version = "0.3.1";
198
+ static buildTime = "2026-11-16T20:48:08.181Z";
199
199
  ldr = null;
200
200
  fires = 0;
201
201
  watching = false;
@@ -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.0";static buildTime="2026-11-16T20:42:33.752Z";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.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);})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@livx.cc/iab-escape",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
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",