@livx.cc/iab-escape 0.2.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 +99 -33
- package/dist/IabEscape.d.ts +15 -3
- package/dist/IabEscape.js +64 -24
- package/dist/iab-escape.min.js +6 -6
- package/dist/loader.d.ts +11 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,68 +1,134 @@
|
|
|
1
1
|
# @livx.cc/iab-escape
|
|
2
2
|
|
|
3
|
-
|
|
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
|
-
|
|
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
|
-
|
|
7
|
+
## Quick start
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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) |
|
|
9
|
+
```html
|
|
10
|
+
<script src="https://cdn.jsdelivr.net/npm/@livx.cc/iab-escape@0.3/dist/iab-escape.min.js" data-auto></script>
|
|
11
|
+
```
|
|
14
12
|
|
|
15
|
-
|
|
13
|
+
Place it early in the page. In any other browser it does nothing: no UI, no navigation.
|
|
16
14
|
|
|
17
|
-
##
|
|
15
|
+
## Install
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
```sh
|
|
18
|
+
npm i @livx.cc/iab-escape # or: bun add @livx.cc/iab-escape
|
|
19
|
+
```
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
```ts
|
|
22
|
+
import { IabEscape } from '@livx.cc/iab-escape';
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
const esc = new IabEscape();
|
|
25
|
+
esc.auto(); // once per page load
|
|
26
|
+
esc.bindLink(document.querySelector('a#open')!); // fallback button/link
|
|
25
27
|
```
|
|
26
28
|
|
|
27
|
-
The
|
|
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.
|
|
48
|
+
|
|
49
|
+
## Options and API
|
|
50
|
+
|
|
51
|
+
Script-tag attributes map to the JS options.
|
|
28
52
|
|
|
29
|
-
|
|
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) |
|
|
30
67
|
|
|
31
|
-
|
|
68
|
+
Methods:
|
|
32
69
|
|
|
33
|
-
|
|
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).
|
|
79
|
+
|
|
80
|
+
## Customize
|
|
81
|
+
|
|
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`.
|
|
83
|
+
|
|
84
|
+
```css
|
|
85
|
+
#iab-escape { --iab-accent: #e33; --iab-radius: 4px; }
|
|
86
|
+
```
|
|
34
87
|
|
|
35
88
|
```ts
|
|
36
|
-
|
|
89
|
+
new IabEscape({ theme: { accent: '#e33', bg: '#000' }, labels: { opening: 'One moment…', open: 'Open', stay: 'Stay' } }).auto();
|
|
90
|
+
```
|
|
37
91
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
92
|
+
Own UI: turn the built-in one off and render from `onState` (`phase`: `opening`, `fallback`, `reentry`, `dismissed`; `url` is the scheme URL for the fallback button).
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
const esc = new IabEscape({ ui: false, onState: ({ phase, url }) => myUi.render(phase, url) });
|
|
96
|
+
esc.auto();
|
|
97
|
+
myUi.onContinue(() => esc.dismiss());
|
|
41
98
|
```
|
|
42
99
|
|
|
43
|
-
|
|
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.
|
|
44
106
|
|
|
45
|
-
|
|
107
|
+
## Tested on
|
|
46
108
|
|
|
47
|
-
-
|
|
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), `onAttempt`, `onResult`, `window`.
|
|
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).
|
|
51
110
|
|
|
52
111
|
## Limits
|
|
53
112
|
|
|
54
113
|
- The schemes are undocumented by Meta and an app update can break them: keep a fallback link and monitor.
|
|
55
|
-
-
|
|
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.
|
|
56
115
|
- A bare `?iab_escaped` (no value) counts as "mark present": the URL is left untouched and `auto()` is skipped.
|
|
57
116
|
- Paid-ad clicks are untested (organic links only).
|
|
58
117
|
- A production domain with universal links may open the native app instead of the browser.
|
|
59
118
|
- Instagram passes no `fbclid` from a DM; Facebook rewrites the `fbclid` at the hand-off.
|
|
60
|
-
- Slow or heavy pages, and a late `auto()` call (after `load`, e.g. an SPA mount), are untested on devices.
|
|
61
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.
|
|
62
|
-
- Never uses meta refresh: it loops on Android when the user cancels.
|
|
63
120
|
- `onResult` watches `visibilitychange`/`pagehide` for 3 s. Meta webviews do not fire these reliably, so `stayed-or-unknown` is not proof of failure.
|
|
64
121
|
- The app's confirm dialog cannot be skipped.
|
|
65
122
|
|
|
66
|
-
##
|
|
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
|
|
67
133
|
|
|
68
|
-
|
|
134
|
+
MIT
|
package/dist/IabEscape.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type Env } from './detect';
|
|
2
|
-
import { type Labels } from './loader';
|
|
2
|
+
import { type Labels, type Theme } from './loader';
|
|
3
3
|
import { type Rule } from './matrix';
|
|
4
|
-
export type { Env, Labels, Rule };
|
|
4
|
+
export type { Env, Labels, Rule, Theme };
|
|
5
|
+
export interface State {
|
|
6
|
+
phase: 'opening' | 'fallback' | 'dismissed' | 'reentry';
|
|
7
|
+
url: string | null;
|
|
8
|
+
}
|
|
5
9
|
export interface AttemptInfo {
|
|
6
10
|
rule: Rule;
|
|
7
11
|
url: string;
|
|
@@ -22,9 +26,13 @@ export declare class IabEscapeOptions {
|
|
|
22
26
|
markParam: string | null;
|
|
23
27
|
onAttempt: ((info: AttemptInfo) => void) | null;
|
|
24
28
|
onResult: ((info: ResultInfo) => void) | null;
|
|
25
|
-
/**
|
|
29
|
+
/** Built-in full-screen loader (spinner, then an "Open in browser" button) while auto() runs. false = off. */
|
|
26
30
|
ui: boolean;
|
|
27
31
|
labels: Partial<Labels>;
|
|
32
|
+
/** Sets the `--iab-*` CSS variables inline on the overlay. */
|
|
33
|
+
theme: Theme;
|
|
34
|
+
/** Phase callback for a custom UI (also called when the built-in UI is on). */
|
|
35
|
+
onState: ((state: State) => void) | null;
|
|
28
36
|
/** Max automatic fires per page lifetime (the first fire + re-entry re-fires). */
|
|
29
37
|
maxAutoFires: number;
|
|
30
38
|
/** Injectable for tests. Default: globalThis.window. */
|
|
@@ -63,6 +71,10 @@ export declare class IabEscape {
|
|
|
63
71
|
*/
|
|
64
72
|
auto(): () => void;
|
|
65
73
|
private loader;
|
|
74
|
+
private state;
|
|
75
|
+
/** Stops re-fires and removes the built-in loader. Wire a custom UI's "Continue here" to this. */
|
|
76
|
+
dismiss(): void;
|
|
77
|
+
private fallback;
|
|
66
78
|
private delay;
|
|
67
79
|
/** One automatic fire: escape(), count it, start watching for re-entry, reveal the button soon after. */
|
|
68
80
|
private fireNow;
|
package/dist/IabEscape.js
CHANGED
|
@@ -13,29 +13,39 @@ function detectEnv(ua) {
|
|
|
13
13
|
|
|
14
14
|
// src/loader.ts
|
|
15
15
|
var DEFAULT_LABELS = { opening: "Opening in your browser…", open: "Open in browser", stay: "Continue here" };
|
|
16
|
+
var VARS = {
|
|
17
|
+
bg: "--iab-bg",
|
|
18
|
+
fg: "--iab-fg",
|
|
19
|
+
accent: "--iab-accent",
|
|
20
|
+
accentFg: "--iab-accent-fg",
|
|
21
|
+
radius: "--iab-radius",
|
|
22
|
+
font: "--iab-font"
|
|
23
|
+
};
|
|
16
24
|
var CSS = `
|
|
17
25
|
#iab-escape{position:fixed;inset:0;z-index:2147483647;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:18px;
|
|
18
26
|
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));
|
|
19
|
-
background
|
|
20
|
-
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color
|
|
21
|
-
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:12px;background
|
|
27
|
+
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}
|
|
28
|
+
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color:var(--iab-accent,#07f);border-radius:50%;animation:ie-r 1s linear infinite}
|
|
29
|
+
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:var(--iab-radius,12px);background:var(--iab-accent,#07f);color:var(--iab-accent-fg,#fff);text-decoration:none;font-weight:600}
|
|
22
30
|
#iab-escape a.ie-stay{font-size:14px;color:inherit;opacity:.7}
|
|
23
31
|
#iab-escape [hidden]{display:none}
|
|
24
32
|
@keyframes ie-r{to{transform:rotate(360deg)}}
|
|
25
|
-
@media (prefers-color-scheme:dark){#iab-escape{background
|
|
33
|
+
@media (prefers-color-scheme:dark){#iab-escape{background:var(--iab-bg,#111);color:var(--iab-fg,#f2f2f2)}}
|
|
26
34
|
@media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`;
|
|
27
35
|
|
|
28
36
|
class Loader {
|
|
29
37
|
doc;
|
|
30
38
|
labels;
|
|
39
|
+
theme;
|
|
31
40
|
onStay;
|
|
32
41
|
root = null;
|
|
33
42
|
open;
|
|
34
43
|
stay;
|
|
35
44
|
spin;
|
|
36
|
-
constructor(doc, labels, onStay) {
|
|
45
|
+
constructor(doc, labels, theme = {}, onStay) {
|
|
37
46
|
this.doc = doc;
|
|
38
47
|
this.labels = labels;
|
|
48
|
+
this.theme = theme;
|
|
39
49
|
this.onStay = onStay;
|
|
40
50
|
}
|
|
41
51
|
get visible() {
|
|
@@ -70,6 +80,9 @@ class Loader {
|
|
|
70
80
|
const root = this.el("div", "");
|
|
71
81
|
root.id = "iab-escape";
|
|
72
82
|
root.setAttribute("role", "status");
|
|
83
|
+
const inline = Object.keys(VARS).filter((k) => this.theme[k]).map((k) => `${VARS[k]}:${this.theme[k]}`).join(";");
|
|
84
|
+
if (inline)
|
|
85
|
+
root.setAttribute("style", inline);
|
|
73
86
|
const style = this.doc.createElement("style");
|
|
74
87
|
style.textContent = CSS;
|
|
75
88
|
this.spin = this.el("div", "ie-spin");
|
|
@@ -133,8 +146,10 @@ class IabEscapeOptions {
|
|
|
133
146
|
markParam = "iab_escaped";
|
|
134
147
|
onAttempt = null;
|
|
135
148
|
onResult = null;
|
|
136
|
-
ui =
|
|
149
|
+
ui = true;
|
|
137
150
|
labels = {};
|
|
151
|
+
theme = {};
|
|
152
|
+
onState = null;
|
|
138
153
|
maxAutoFires = 3;
|
|
139
154
|
window = null;
|
|
140
155
|
}
|
|
@@ -151,6 +166,24 @@ function optionsFromDataset(d) {
|
|
|
151
166
|
o.url = d.url;
|
|
152
167
|
if (d.ui !== undefined)
|
|
153
168
|
o.ui = d.ui !== "false";
|
|
169
|
+
const theme = {};
|
|
170
|
+
if (d.accent)
|
|
171
|
+
theme.accent = d.accent;
|
|
172
|
+
if (d.bg)
|
|
173
|
+
theme.bg = d.bg;
|
|
174
|
+
if (d.fg)
|
|
175
|
+
theme.fg = d.fg;
|
|
176
|
+
if (Object.keys(theme).length)
|
|
177
|
+
o.theme = theme;
|
|
178
|
+
const labels = {};
|
|
179
|
+
if (d.labelOpening)
|
|
180
|
+
labels.opening = d.labelOpening;
|
|
181
|
+
if (d.labelOpen)
|
|
182
|
+
labels.open = d.labelOpen;
|
|
183
|
+
if (d.labelStay)
|
|
184
|
+
labels.stay = d.labelStay;
|
|
185
|
+
if (Object.keys(labels).length)
|
|
186
|
+
o.labels = labels;
|
|
154
187
|
return o;
|
|
155
188
|
}
|
|
156
189
|
var WATCH_MS = 3000;
|
|
@@ -161,8 +194,8 @@ var hasParam = (url, key) => new URLSearchParams(url.split("#")[0].split("?")[1]
|
|
|
161
194
|
|
|
162
195
|
class IabEscape {
|
|
163
196
|
options;
|
|
164
|
-
static version = "0.
|
|
165
|
-
static buildTime = "2026-11-16T20:
|
|
197
|
+
static version = "0.3.1";
|
|
198
|
+
static buildTime = "2026-11-16T20:48:08.181Z";
|
|
166
199
|
ldr = null;
|
|
167
200
|
fires = 0;
|
|
168
201
|
watching = false;
|
|
@@ -234,6 +267,7 @@ class IabEscape {
|
|
|
234
267
|
this.dismissed = false;
|
|
235
268
|
if (this.o.ui)
|
|
236
269
|
this.loader().show();
|
|
270
|
+
this.state("opening");
|
|
237
271
|
let done = false;
|
|
238
272
|
let id;
|
|
239
273
|
const fire = () => {
|
|
@@ -263,9 +297,21 @@ class IabEscape {
|
|
|
263
297
|
};
|
|
264
298
|
}
|
|
265
299
|
loader() {
|
|
266
|
-
return this.ldr ??= new Loader(this.win.document, { ...DEFAULT_LABELS, ...this.o.labels }, () =>
|
|
267
|
-
|
|
268
|
-
|
|
300
|
+
return this.ldr ??= new Loader(this.win.document, { ...DEFAULT_LABELS, ...this.o.labels }, this.o.theme, () => this.dismiss());
|
|
301
|
+
}
|
|
302
|
+
state(phase) {
|
|
303
|
+
this.o.onState?.({ phase, url: this.buildUrl() });
|
|
304
|
+
}
|
|
305
|
+
dismiss() {
|
|
306
|
+
this.dismissed = true;
|
|
307
|
+
this.ldr?.hide();
|
|
308
|
+
this.state("dismissed");
|
|
309
|
+
}
|
|
310
|
+
fallback() {
|
|
311
|
+
const url = this.buildUrl();
|
|
312
|
+
if (url && this.o.ui)
|
|
313
|
+
this.loader().reveal(url);
|
|
314
|
+
this.state("fallback");
|
|
269
315
|
}
|
|
270
316
|
delay(rule) {
|
|
271
317
|
return this.o.delayMs ?? rule.delayMs;
|
|
@@ -277,13 +323,10 @@ class IabEscape {
|
|
|
277
323
|
}
|
|
278
324
|
this.fires++;
|
|
279
325
|
this.watchReentry();
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
this.ldr.reveal(url);
|
|
285
|
-
}, REVEAL_MS);
|
|
286
|
-
}
|
|
326
|
+
this.win.setTimeout(() => {
|
|
327
|
+
if (!this.dismissed)
|
|
328
|
+
this.fallback();
|
|
329
|
+
}, REVEAL_MS);
|
|
287
330
|
return true;
|
|
288
331
|
}
|
|
289
332
|
watchReentry() {
|
|
@@ -318,14 +361,11 @@ class IabEscape {
|
|
|
318
361
|
win.setTimeout(() => {
|
|
319
362
|
this.locked = false;
|
|
320
363
|
}, REENTER_LOCK_MS);
|
|
321
|
-
if (this.fires >= this.o.maxAutoFires)
|
|
322
|
-
|
|
323
|
-
if (this.o.ui && url)
|
|
324
|
-
this.loader().reveal(url);
|
|
325
|
-
return;
|
|
326
|
-
}
|
|
364
|
+
if (this.fires >= this.o.maxAutoFires)
|
|
365
|
+
return this.fallback();
|
|
327
366
|
if (this.o.ui)
|
|
328
367
|
this.loader().show();
|
|
368
|
+
this.state("reentry");
|
|
329
369
|
if (this.delay(rule) <= 0)
|
|
330
370
|
this.fireNow();
|
|
331
371
|
else
|
package/dist/iab-escape.min.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
(()=>{var{defineProperty:
|
|
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=`
|
|
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
|
-
background
|
|
5
|
-
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color
|
|
6
|
-
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:12px;background
|
|
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}
|
|
5
|
+
#iab-escape .ie-spin{width:36px;height:36px;border:4px solid #8884;border-top-color:var(--iab-accent,#07f);border-radius:50%;animation:ie-r 1s linear infinite}
|
|
6
|
+
#iab-escape a.ie-open{display:block;padding:14px 28px;border-radius:var(--iab-radius,12px);background:var(--iab-accent,#07f);color:var(--iab-accent-fg,#fff);text-decoration:none;font-weight:600}
|
|
7
7
|
#iab-escape a.ie-stay{font-size:14px;color:inherit;opacity:.7}
|
|
8
8
|
#iab-escape [hidden]{display:none}
|
|
9
9
|
@keyframes ie-r{to{transform:rotate(360deg)}}
|
|
10
|
-
@media (prefers-color-scheme:dark){#iab-escape{background
|
|
11
|
-
@media (prefers-reduced-motion:reduce){#iab-escape .ie-spin{animation:none}}`,this.spin=this.el("div","ie-spin");let
|
|
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);})();
|
package/dist/loader.d.ts
CHANGED
|
@@ -4,16 +4,26 @@ export interface Labels {
|
|
|
4
4
|
stay: string;
|
|
5
5
|
}
|
|
6
6
|
export declare const DEFAULT_LABELS: Labels;
|
|
7
|
+
/** Styling API: the `#iab-escape` root, the classes below, and these CSS variables (all optional). */
|
|
8
|
+
export interface Theme {
|
|
9
|
+
bg?: string;
|
|
10
|
+
fg?: string;
|
|
11
|
+
accent?: string;
|
|
12
|
+
accentFg?: string;
|
|
13
|
+
radius?: string;
|
|
14
|
+
font?: string;
|
|
15
|
+
}
|
|
7
16
|
/** Full-screen "opening in your browser" overlay. No deps; built with createElement only. */
|
|
8
17
|
export declare class Loader {
|
|
9
18
|
private doc;
|
|
10
19
|
private labels;
|
|
20
|
+
private theme;
|
|
11
21
|
private onStay?;
|
|
12
22
|
private root;
|
|
13
23
|
private open;
|
|
14
24
|
private stay;
|
|
15
25
|
private spin;
|
|
16
|
-
constructor(doc: Document, labels: Labels, onStay?: (() => void) | undefined);
|
|
26
|
+
constructor(doc: Document, labels: Labels, theme?: Theme, onStay?: (() => void) | undefined);
|
|
17
27
|
get visible(): boolean;
|
|
18
28
|
/** Spinner state (also resets a previously revealed button). */
|
|
19
29
|
show(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@livx.cc/iab-escape",
|
|
3
|
-
"version": "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",
|