swarmbox 0.0.0-stage → 0.12.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/LICENSE +21 -0
- package/README.md +121 -2
- package/dist/checks.d.ts +48 -0
- package/dist/checks.d.ts.map +1 -0
- package/dist/checks.js +43 -0
- package/dist/checks.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +48 -0
- package/dist/cli.js.map +1 -0
- package/dist/control-room/page.d.ts +2 -0
- package/dist/control-room/page.d.ts.map +1 -0
- package/dist/control-room/page.js +212 -0
- package/dist/control-room/page.js.map +1 -0
- package/dist/control-room/server.d.ts +8 -0
- package/dist/control-room/server.d.ts.map +1 -0
- package/dist/control-room/server.js +180 -0
- package/dist/control-room/server.js.map +1 -0
- package/dist/device/device.d.ts +20 -0
- package/dist/device/device.d.ts.map +1 -0
- package/dist/device/device.js +108 -0
- package/dist/device/device.js.map +1 -0
- package/dist/device/props.d.ts +31 -0
- package/dist/device/props.d.ts.map +1 -0
- package/dist/device/props.js +143 -0
- package/dist/device/props.js.map +1 -0
- package/dist/fleet/browser.d.ts +116 -0
- package/dist/fleet/browser.d.ts.map +1 -0
- package/dist/fleet/browser.js +298 -0
- package/dist/fleet/browser.js.map +1 -0
- package/dist/fleet/sight.d.ts +70 -0
- package/dist/fleet/sight.d.ts.map +1 -0
- package/dist/fleet/sight.js +288 -0
- package/dist/fleet/sight.js.map +1 -0
- package/dist/harness.d.ts +258 -0
- package/dist/harness.d.ts.map +1 -0
- package/dist/harness.js +907 -0
- package/dist/harness.js.map +1 -0
- package/dist/hooks.d.ts +69 -0
- package/dist/hooks.d.ts.map +1 -0
- package/dist/hooks.js +80 -0
- package/dist/hooks.js.map +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/device.d.ts +6 -0
- package/dist/mcp/device.d.ts.map +1 -0
- package/dist/mcp/device.js +61 -0
- package/dist/mcp/device.js.map +1 -0
- package/dist/mcp/server.d.ts +15 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +670 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mcp/standins.d.ts +11 -0
- package/dist/mcp/standins.d.ts.map +1 -0
- package/dist/mcp/standins.js +142 -0
- package/dist/mcp/standins.js.map +1 -0
- package/dist/product.d.ts +226 -0
- package/dist/product.d.ts.map +1 -0
- package/dist/product.js +10 -0
- package/dist/product.js.map +1 -0
- package/dist/provenance.d.ts +22 -0
- package/dist/provenance.d.ts.map +1 -0
- package/dist/provenance.js +55 -0
- package/dist/provenance.js.map +1 -0
- package/dist/runs/budget.d.ts +23 -0
- package/dist/runs/budget.d.ts.map +1 -0
- package/dist/runs/budget.js +56 -0
- package/dist/runs/budget.js.map +1 -0
- package/dist/runs/report.d.ts +3 -0
- package/dist/runs/report.d.ts.map +1 -0
- package/dist/runs/report.js +125 -0
- package/dist/runs/report.js.map +1 -0
- package/dist/runs/run.d.ts +86 -0
- package/dist/runs/run.d.ts.map +1 -0
- package/dist/runs/run.js +227 -0
- package/dist/runs/run.js.map +1 -0
- package/dist/scenarios/spec.d.ts +33 -0
- package/dist/scenarios/spec.d.ts.map +1 -0
- package/dist/scenarios/spec.js +89 -0
- package/dist/scenarios/spec.js.map +1 -0
- package/dist/serve.d.ts +31 -0
- package/dist/serve.d.ts.map +1 -0
- package/dist/serve.js +39 -0
- package/dist/serve.js.map +1 -0
- package/dist/standins/builtin/email/index.d.ts +2 -0
- package/dist/standins/builtin/email/index.d.ts.map +1 -0
- package/dist/standins/builtin/email/index.js +213 -0
- package/dist/standins/builtin/email/index.js.map +1 -0
- package/dist/standins/builtin/email/manifest.json +41 -0
- package/dist/standins/builtin/expo-push/index.d.ts +2 -0
- package/dist/standins/builtin/expo-push/index.d.ts.map +1 -0
- package/dist/standins/builtin/expo-push/index.js +203 -0
- package/dist/standins/builtin/expo-push/index.js.map +1 -0
- package/dist/standins/builtin/expo-push/manifest.json +45 -0
- package/dist/standins/builtin/helcim/index.d.ts +7 -0
- package/dist/standins/builtin/helcim/index.d.ts.map +1 -0
- package/dist/standins/builtin/helcim/index.js +438 -0
- package/dist/standins/builtin/helcim/index.js.map +1 -0
- package/dist/standins/builtin/helcim/manifest.json +37 -0
- package/dist/standins/builtin/index.d.ts +8 -0
- package/dist/standins/builtin/index.d.ts.map +1 -0
- package/dist/standins/builtin/index.js +22 -0
- package/dist/standins/builtin/index.js.map +1 -0
- package/dist/standins/builtin/s3/checksums.d.ts +8 -0
- package/dist/standins/builtin/s3/checksums.d.ts.map +1 -0
- package/dist/standins/builtin/s3/checksums.js +67 -0
- package/dist/standins/builtin/s3/checksums.js.map +1 -0
- package/dist/standins/builtin/s3/index.d.ts +6 -0
- package/dist/standins/builtin/s3/index.d.ts.map +1 -0
- package/dist/standins/builtin/s3/index.js +688 -0
- package/dist/standins/builtin/s3/index.js.map +1 -0
- package/dist/standins/builtin/s3/manifest.json +35 -0
- package/dist/standins/builtin/twilio/index.d.ts +10 -0
- package/dist/standins/builtin/twilio/index.d.ts.map +1 -0
- package/dist/standins/builtin/twilio/index.js +477 -0
- package/dist/standins/builtin/twilio/index.js.map +1 -0
- package/dist/standins/builtin/twilio/manifest.json +133 -0
- package/dist/standins/guard.d.ts +16 -0
- package/dist/standins/guard.d.ts.map +1 -0
- package/dist/standins/guard.js +78 -0
- package/dist/standins/guard.js.map +1 -0
- package/dist/standins/manifest.d.ts +94 -0
- package/dist/standins/manifest.d.ts.map +1 -0
- package/dist/standins/manifest.js +121 -0
- package/dist/standins/manifest.js.map +1 -0
- package/dist/standins/protocol.d.ts +114 -0
- package/dist/standins/protocol.d.ts.map +1 -0
- package/dist/standins/protocol.js +11 -0
- package/dist/standins/protocol.js.map +1 -0
- package/dist/standins/runner.d.ts +78 -0
- package/dist/standins/runner.d.ts.map +1 -0
- package/dist/standins/runner.js +746 -0
- package/dist/standins/runner.js.map +1 -0
- package/dist/standins/sdk.d.ts +73 -0
- package/dist/standins/sdk.d.ts.map +1 -0
- package/dist/standins/sdk.js +217 -0
- package/dist/standins/sdk.js.map +1 -0
- package/dist/standins/shape.d.ts +25 -0
- package/dist/standins/shape.d.ts.map +1 -0
- package/dist/standins/shape.js +131 -0
- package/dist/standins/shape.js.map +1 -0
- package/dist/time.d.ts +12 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +64 -0
- package/dist/time.js.map +1 -0
- package/package.json +71 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/fleet/browser.ts"],"names":[],"mappings":"AAgBA,OAAO,EAA0B,KAAK,cAAc,EAAE,KAAK,IAAI,EAAc,MAAM,iBAAiB,CAAC;AACrG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAElE,sGAAsG;AACtG,wBAAsB,UAAU,CAC9B,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,WAAW,EAAE,GACrB,OAAO,CAAC,IAAI,CAAC,CAWf;AAED,uGAAuG;AACvG,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb,0FAA0F;IAC1F,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uFAAuF;IACvF,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,MAAM,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,M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;IACnB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,wBAAsB,WAAW,CAAC,OAAO,EAAE,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,CAiKvE"}
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
// The browser fleet: one screen per person, watchable and take-over-able.
|
|
2
|
+
//
|
|
3
|
+
// Swarmbox must own Chromium's launch, and this is forced rather than chosen. Tenant hostnames have no DNS
|
|
4
|
+
// record anywhere (no zone, no /etc/hosts entry) and resolve ONLY because Chromium is started with
|
|
5
|
+
// --host-resolver-rules. A generic browser automation server, or the operator's own Chrome, cannot reach a
|
|
6
|
+
// tenant's host at all. That is why Playwright is embedded here instead of chained as a separate MCP server.
|
|
7
|
+
//
|
|
8
|
+
// One Chromium per tenant origin, launched when that tenant's first screen opens. Web crypto (crypto.subtle)
|
|
9
|
+
// exists only in a secure context, and plain http is not one; Chromium will treat an origin as secure only
|
|
10
|
+
// when named exactly at launch (no wildcards), and a tenant's origin is known only once its world exists, so
|
|
11
|
+
// a single browser started up front cannot cover it. It needs the full Chromium build, not the headless
|
|
12
|
+
// shell, hence channel 'chromium'.
|
|
13
|
+
//
|
|
14
|
+
// A factory rather than a class: products run TypeScript through Node's strip-only loader, which does not
|
|
15
|
+
// support parameter properties.
|
|
16
|
+
import { chromium } from 'playwright-core';
|
|
17
|
+
/** A sign-in's cookies, on the tenant's own origin: how a screen is signed in, and kept signed in. */
|
|
18
|
+
export async function setCookies(context, origin, cookies) {
|
|
19
|
+
await context.addCookies(cookies.map((c) => ({
|
|
20
|
+
name: c.name,
|
|
21
|
+
value: c.value,
|
|
22
|
+
url: origin,
|
|
23
|
+
httpOnly: c.httpOnly ?? true,
|
|
24
|
+
secure: false,
|
|
25
|
+
sameSite: c.sameSite ?? 'Lax',
|
|
26
|
+
})));
|
|
27
|
+
}
|
|
28
|
+
/** Makes `*.{baseDomain}` resolve to loopback inside this browser, and nowhere else on the machine. */
|
|
29
|
+
export function resolverRule(baseDomain) {
|
|
30
|
+
return `--host-resolver-rules=MAP *.${baseDomain} 127.0.0.1`;
|
|
31
|
+
}
|
|
32
|
+
/** What a page a stand-in plays may load and talk to: its own origin, nothing else. */
|
|
33
|
+
const ROUTED_CSP = "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; " +
|
|
34
|
+
"img-src 'self' data:; connect-src 'self'; form-action 'self'; frame-src 'self'; base-uri 'none'";
|
|
35
|
+
/** Hops Swarmbox follows itself between a stand-in's own pages before calling it a loop. */
|
|
36
|
+
const ROUTED_HOPS = 5;
|
|
37
|
+
/**
|
|
38
|
+
* A request to a provider origin a stand-in plays, answered by that stand-in (FleetOptions.routes). Its redirects
|
|
39
|
+
* are never left to the browser where the browser would leave the world, because Playwright routes only the first
|
|
40
|
+
* URL of a navigation, not the hops after it:
|
|
41
|
+
* - out of the world: refused here, with a 502;
|
|
42
|
+
* - to a routed origin (the browser would go to the real provider) or a stand-in's own address (the browser would
|
|
43
|
+
* skip this proxy): a navigation is sent on afresh, so it is routed; anything else (a fetch, an image) is
|
|
44
|
+
* followed here, each hop checked;
|
|
45
|
+
* - to the world's own hosts or what the product loads from outside: the browser follows it. The product is
|
|
46
|
+
* trusted: an open redirect of its own is a way out a stand-in could use, so a product shouldn't have one.
|
|
47
|
+
*/
|
|
48
|
+
async function answerRouted(route, options) {
|
|
49
|
+
const req = route.request();
|
|
50
|
+
const routes = options.routes ?? [];
|
|
51
|
+
const headers = Object.fromEntries(Object.entries(await req.allHeaders()).filter(([k]) => !/^(host|cookie|:)/i.test(k)));
|
|
52
|
+
let url = new URL(req.url());
|
|
53
|
+
let method = req.method();
|
|
54
|
+
let body = method === 'GET' || method === 'HEAD'
|
|
55
|
+
? undefined
|
|
56
|
+
: new Uint8Array(req.postDataBuffer() ?? Buffer.alloc(0));
|
|
57
|
+
const refuse = (what) => route.fulfill({
|
|
58
|
+
status: 502,
|
|
59
|
+
headers: { 'content-type': 'text/plain', 'content-security-policy': ROUTED_CSP },
|
|
60
|
+
body: `Swarmbox refused ${what}.`,
|
|
61
|
+
});
|
|
62
|
+
for (let hop = 0;; hop++) {
|
|
63
|
+
// A routed origin is answered by its stand-in; a stand-in's own address, by itself.
|
|
64
|
+
const to = routes.find((x) => x.origin === url.origin)?.to ?? url.origin;
|
|
65
|
+
if (to === url.origin && !(options.standins ?? []).includes(url.origin))
|
|
66
|
+
return refuse('a request outside the world');
|
|
67
|
+
const res = await fetch(`${to}${url.pathname}${url.search}`, {
|
|
68
|
+
method,
|
|
69
|
+
headers,
|
|
70
|
+
...(body ? { body } : {}),
|
|
71
|
+
redirect: 'manual',
|
|
72
|
+
});
|
|
73
|
+
const location = res.headers.get('location');
|
|
74
|
+
if (res.status >= 300 && res.status < 400 && location !== null) {
|
|
75
|
+
let next = null;
|
|
76
|
+
try {
|
|
77
|
+
next = new URL(location, url);
|
|
78
|
+
}
|
|
79
|
+
catch {
|
|
80
|
+
// not a URL: refused below
|
|
81
|
+
}
|
|
82
|
+
if (!next || !insideWorld(next.href, options))
|
|
83
|
+
return refuse('a redirect out of the world');
|
|
84
|
+
if (routes.some((x) => x.origin === next.origin) || (options.standins ?? []).includes(next.origin)) {
|
|
85
|
+
if (req.isNavigationRequest())
|
|
86
|
+
return route.fulfill({
|
|
87
|
+
status: 200,
|
|
88
|
+
headers: { 'content-type': 'text/html', 'content-security-policy': ROUTED_CSP },
|
|
89
|
+
body: `<!doctype html><script>location.replace(${JSON.stringify(next.href).replace(/</g, '\\u003c')})</script>`,
|
|
90
|
+
});
|
|
91
|
+
if (hop >= ROUTED_HOPS)
|
|
92
|
+
return refuse('a redirect loop');
|
|
93
|
+
if (res.status === 303 || ((res.status === 301 || res.status === 302) && method === 'POST')) {
|
|
94
|
+
method = 'GET';
|
|
95
|
+
body = undefined;
|
|
96
|
+
}
|
|
97
|
+
url = next;
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const out = Object.fromEntries([...res.headers].filter(
|
|
102
|
+
// fetch has already decoded the body, and the stand-in's own CSP is replaced by ours.
|
|
103
|
+
([k]) => !/^(content-encoding|content-length|transfer-encoding|content-security-policy)$/i.test(k)));
|
|
104
|
+
return route.fulfill({
|
|
105
|
+
status: res.status,
|
|
106
|
+
headers: { ...out, 'content-security-policy': ROUTED_CSP },
|
|
107
|
+
body: Buffer.from(await res.arrayBuffer()),
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Whether a URL is inside a world whose browsers play a provider's pages (see FleetOptions.allowOrigins). */
|
|
112
|
+
export function insideWorld(url, options) {
|
|
113
|
+
let u;
|
|
114
|
+
try {
|
|
115
|
+
u = new URL(url);
|
|
116
|
+
}
|
|
117
|
+
catch {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
if (u.protocol === 'data:' || u.protocol === 'blob:' || u.protocol === 'about:')
|
|
121
|
+
return true;
|
|
122
|
+
const plain = u.protocol === 'ws:' ? 'http:' : u.protocol === 'wss:' ? 'https:' : u.protocol;
|
|
123
|
+
const origin = `${plain}//${u.host}`;
|
|
124
|
+
const world = plain === 'http:' &&
|
|
125
|
+
Number(u.port || 80) === options.port &&
|
|
126
|
+
(u.hostname === options.baseDomain || u.hostname.endsWith(`.${options.baseDomain}`));
|
|
127
|
+
return (world ||
|
|
128
|
+
(options.routes ?? []).some((r) => r.origin === origin) ||
|
|
129
|
+
(options.standins ?? []).includes(origin) ||
|
|
130
|
+
(options.allowOrigins ?? []).some((o) => {
|
|
131
|
+
try {
|
|
132
|
+
return new URL(o).origin === origin;
|
|
133
|
+
}
|
|
134
|
+
catch {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
}));
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* The devices a screen can be. A sign-in's own viewport (a product's tablet app) is the default for that
|
|
141
|
+
* app; a device named when the screen opens wins over it, so the same app can be tried on a phone or turned
|
|
142
|
+
* to portrait. Sizes are CSS pixels of common devices: a 6.1" phone, an 11" tablet each way, a laptop.
|
|
143
|
+
*/
|
|
144
|
+
export const DEVICES = {
|
|
145
|
+
desktop: { viewport: { width: 1440, height: 900 } },
|
|
146
|
+
phone: { viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, deviceScaleFactor: 3 },
|
|
147
|
+
tablet: { viewport: { width: 1180, height: 820 }, hasTouch: true, deviceScaleFactor: 2 },
|
|
148
|
+
'tablet-portrait': { viewport: { width: 820, height: 1180 }, hasTouch: true, deviceScaleFactor: 2 },
|
|
149
|
+
};
|
|
150
|
+
export async function launchFleet(options) {
|
|
151
|
+
const browsers = new Map();
|
|
152
|
+
const launch = (origin) => chromium.launch({
|
|
153
|
+
channel: 'chromium',
|
|
154
|
+
headless: options.headless ?? false,
|
|
155
|
+
args: [
|
|
156
|
+
resolverRule(options.baseDomain),
|
|
157
|
+
`--unsafely-treat-insecure-origin-as-secure=${origin}`,
|
|
158
|
+
// Every screen is watched at once, so none may be treated as "in the background". Headed windows
|
|
159
|
+
// overlap on a real desktop, and Chromium throttles painting in occluded windows; a page that does
|
|
160
|
+
// not paint emits no screencast frames. Not reproducible headless (the tests run headless), so this
|
|
161
|
+
// guards the headed case rather than fixing an observed failure.
|
|
162
|
+
'--disable-background-timer-throttling',
|
|
163
|
+
'--disable-backgrounding-occluded-windows',
|
|
164
|
+
'--disable-renderer-backgrounding',
|
|
165
|
+
],
|
|
166
|
+
...(options.slowMo === undefined ? {} : { slowMo: options.slowMo }),
|
|
167
|
+
});
|
|
168
|
+
const browserFor = (origin) => {
|
|
169
|
+
let b = browsers.get(origin);
|
|
170
|
+
if (!b) {
|
|
171
|
+
b = launch(origin);
|
|
172
|
+
// A launch that failed is not kept: the next screen for that tenant tries again.
|
|
173
|
+
b.catch(() => browsers.delete(origin));
|
|
174
|
+
browsers.set(origin, b);
|
|
175
|
+
}
|
|
176
|
+
return b;
|
|
177
|
+
};
|
|
178
|
+
const screens = [];
|
|
179
|
+
let nextAddress = 1;
|
|
180
|
+
const originFor = (tenant) => `http://${tenant}.${options.baseDomain}:${options.port}`;
|
|
181
|
+
return {
|
|
182
|
+
originFor,
|
|
183
|
+
screens,
|
|
184
|
+
/**
|
|
185
|
+
* One BrowserContext per person, never one browser per person: contexts are isolated in cookies
|
|
186
|
+
* and storage, which is what makes several people genuinely concurrent, and it is the pattern the
|
|
187
|
+
* test suites already rely on.
|
|
188
|
+
*
|
|
189
|
+
* The sign-in's cookies are injected rather than typed: host-only (given by `url`, so no Domain
|
|
190
|
+
* attribute; a `domain` here would make it a domain cookie that subdomains also receive), HttpOnly and
|
|
191
|
+
* SameSite=Lax unless the product says otherwise, and never Secure, because a world is plain HTTP and a
|
|
192
|
+
* Secure cookie over HTTP is dropped silently.
|
|
193
|
+
*
|
|
194
|
+
* Each screen gets its own client address unless one is given. Every browser here connects from
|
|
195
|
+
* 127.0.0.1, and a product's per-address limits (sign-in attempts, lookups) would see the whole sandbox
|
|
196
|
+
* as one huge office. A product behind a proxy trusts one hop, so the address goes in X-Forwarded-For,
|
|
197
|
+
* the same path a real client's takes. Defaults come from 198.18.0.0/15, a range reserved for testing.
|
|
198
|
+
* Giving several screens one address is how a crew behind one router is simulated.
|
|
199
|
+
*/
|
|
200
|
+
async open(who, path = '/', { address, onContext, device, colorScheme, clock } = {}) {
|
|
201
|
+
const signIn = who.signIn;
|
|
202
|
+
const localStorage = signIn?.localStorage;
|
|
203
|
+
const viewport = signIn?.viewport;
|
|
204
|
+
const shape = device ? DEVICES[device] : viewport ? { viewport, hasTouch: true } : {};
|
|
205
|
+
const origin = originFor(who.persona.tenant);
|
|
206
|
+
const n = nextAddress++;
|
|
207
|
+
const ip = address ?? `198.18.${Math.floor(n / 256) % 256}.${n % 256}`;
|
|
208
|
+
const context = await (await browserFor(origin)).newContext({
|
|
209
|
+
baseURL: origin,
|
|
210
|
+
// The server runs in UTC; a person's browser runs where they are. "Today", "Yesterday" and the
|
|
211
|
+
// year on a byline are decided here, so this machine's zone must not leak in.
|
|
212
|
+
timezoneId: who.persona.timeZone,
|
|
213
|
+
// A contained world has no service workers: one on a routed origin would answer outside the routes.
|
|
214
|
+
...(options.routes?.length ? { serviceWorkers: 'block' } : {}),
|
|
215
|
+
...shape,
|
|
216
|
+
...(colorScheme ? { colorScheme } : {}),
|
|
217
|
+
});
|
|
218
|
+
// Before the app's scripts run, and only where absent: how a tablet that is already signed in is
|
|
219
|
+
// opened (an app that keeps its tokens there), without putting back what the app later rewrites.
|
|
220
|
+
if (localStorage)
|
|
221
|
+
// Every frame runs it, sandboxed ones too, whose storage is refused: only the tenant's own page.
|
|
222
|
+
await context.addInitScript(({ items, at }) => {
|
|
223
|
+
if (globalThis.location?.origin !== at)
|
|
224
|
+
return;
|
|
225
|
+
for (const [k, v] of Object.entries(items))
|
|
226
|
+
if (globalThis.localStorage.getItem(k) === null)
|
|
227
|
+
globalThis.localStorage.setItem(k, v);
|
|
228
|
+
}, { items: localStorage, at: origin });
|
|
229
|
+
// The address goes to the tenant's own server only. As a header on every request it also went to
|
|
230
|
+
// other origins (an app's web fonts), where a non-simple header makes the browser ask first and the
|
|
231
|
+
// answer is no: the fonts failed, which production never sees.
|
|
232
|
+
//
|
|
233
|
+
// The cost of routing: Playwright turns the HTTP cache off for a context with any route, so a screen
|
|
234
|
+
// fetches every asset on every load. Behaviour is the same; first loads are slower than a real
|
|
235
|
+
// device's repeat visits. Anything that depends on the HTTP cache is out of reach here.
|
|
236
|
+
// allHeaders, not headers: the plain list leaves out the cookie, and the screen would be signed out.
|
|
237
|
+
await context.route(`${origin}/**`, async (route) => route.continue({ headers: { ...(await route.request().allHeaders()), 'x-forwarded-for': ip } }));
|
|
238
|
+
if (signIn?.cookies?.length)
|
|
239
|
+
await setCookies(context, origin, signIn.cookies);
|
|
240
|
+
if (options.routes?.length) {
|
|
241
|
+
// Contained: nothing leaves the world but to its stand-ins and what the product loads from outside.
|
|
242
|
+
await context.route((url) => !insideWorld(url.href, options), (route) => route.abort('blockedbyclient'));
|
|
243
|
+
await context.routeWebSocket((url) => !insideWorld(url.href, options), (ws) => ws.close({ code: 1008, reason: 'outside the world' }));
|
|
244
|
+
}
|
|
245
|
+
// Matched by exact origin, never by a pattern a manifest could widen. A contained world's stand-ins are
|
|
246
|
+
// reached through the same proxy, so every redirect any of them answers is checked.
|
|
247
|
+
const proxied = [
|
|
248
|
+
...(options.routes ?? []).map((r) => r.origin),
|
|
249
|
+
...(options.routes?.length ? (options.standins ?? []) : []),
|
|
250
|
+
];
|
|
251
|
+
for (const o of proxied)
|
|
252
|
+
await context.route((url) => url.origin === o, (route) => answerRouted(route, options).catch(() => route.abort('connectionrefused').catch(() => undefined)));
|
|
253
|
+
let page;
|
|
254
|
+
try {
|
|
255
|
+
// The screen's own set-up (its device): inside, so a failure there closes the half-made context too.
|
|
256
|
+
await onContext?.(context);
|
|
257
|
+
// Before the first page: an app that reads "today" as it starts would otherwise draw this machine's
|
|
258
|
+
// date, or the epoch, until something made it look again.
|
|
259
|
+
if (clock) {
|
|
260
|
+
if (clock.paused)
|
|
261
|
+
await context.clock.setFixedTime(new Date(clock.at));
|
|
262
|
+
else
|
|
263
|
+
await context.clock.setSystemTime(new Date(clock.at));
|
|
264
|
+
}
|
|
265
|
+
page = await context.newPage();
|
|
266
|
+
// load, not domcontentloaded: an app drawn by its scripts is drawn after the HTML.
|
|
267
|
+
await page.goto(path, { waitUntil: 'load' });
|
|
268
|
+
}
|
|
269
|
+
catch (e) {
|
|
270
|
+
// A screen that can't be put on the world's time or opened is not left half-made, holding a context.
|
|
271
|
+
await context.close().catch(() => undefined);
|
|
272
|
+
throw e;
|
|
273
|
+
}
|
|
274
|
+
const screen = {
|
|
275
|
+
signIn,
|
|
276
|
+
address: ip,
|
|
277
|
+
context,
|
|
278
|
+
page,
|
|
279
|
+
close: async () => {
|
|
280
|
+
await context.close().catch(() => undefined);
|
|
281
|
+
const i = screens.indexOf(screen);
|
|
282
|
+
if (i >= 0)
|
|
283
|
+
screens.splice(i, 1);
|
|
284
|
+
},
|
|
285
|
+
};
|
|
286
|
+
screens.push(screen);
|
|
287
|
+
return screen;
|
|
288
|
+
},
|
|
289
|
+
async close() {
|
|
290
|
+
await Promise.all(screens.map((s) => s.context.close().catch(() => undefined)));
|
|
291
|
+
screens.length = 0;
|
|
292
|
+
const all = [...browsers.values()];
|
|
293
|
+
browsers.clear();
|
|
294
|
+
await Promise.all(all.map(async (b) => (await b.catch(() => null))?.close().catch(() => undefined)));
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/fleet/browser.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,EAAE;AACF,2GAA2G;AAC3G,mGAAmG;AACnG,2GAA2G;AAC3G,6GAA6G;AAC7G,EAAE;AACF,6GAA6G;AAC7G,2GAA2G;AAC3G,6GAA6G;AAC7G,wGAAwG;AACxG,mCAAmC;AACnC,EAAE;AACF,0GAA0G;AAC1G,gCAAgC;AAEhC,OAAO,EAAE,QAAQ,EAA4D,MAAM,iBAAiB,CAAC;AAGrG,sGAAsG;AACtG,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,OAAuB,EACvB,MAAc,EACd,OAAsB;IAEtB,MAAM,OAAO,CAAC,UAAU,CACtB,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAClB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,GAAG,EAAE,MAAM;QACX,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,IAAI;QAC5B,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,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AQ,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACvG,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { Locator, Page } from 'playwright-core';
|
|
2
|
+
export interface OpenDialog {
|
|
3
|
+
title: string;
|
|
4
|
+
/** Modal: everything behind it is out of reach until it closes. */
|
|
5
|
+
modal: boolean;
|
|
6
|
+
/** Its accessibility tree, as a read shows a page. */
|
|
7
|
+
tree: string;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* The dialogs a person can see, the ones holding the screen first, the most recently opened (latest in
|
|
11
|
+
* the page) first among those.
|
|
12
|
+
*/
|
|
13
|
+
export declare function openDialogs(page: Page): Promise<OpenDialog[]>;
|
|
14
|
+
/** The dialogs, written for the top of a read: what can be used right now. */
|
|
15
|
+
export declare function dialogsText(dialogs: OpenDialog[]): string;
|
|
16
|
+
/** What a screen looks like at a glance: enough to say afterwards what an action changed. */
|
|
17
|
+
export interface Glance {
|
|
18
|
+
url: string;
|
|
19
|
+
dialogs: string[];
|
|
20
|
+
/** Visible status and alert text. */
|
|
21
|
+
said: string[];
|
|
22
|
+
}
|
|
23
|
+
export declare function glance(page: Page): Promise<Glance>;
|
|
24
|
+
/** Lines saying what moved between two glances; empty when nothing a person would notice did. */
|
|
25
|
+
export declare function changes(before: Glance, after: Glance): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Of several controls an action's words match, the one meant: the only one in the dialog in front.
|
|
28
|
+
* Dialogs stack (a job's panel, then "Send estimate" over it), and only the one in front can be used:
|
|
29
|
+
* the innermost of the open modal ones, the latest opened among equals. Null when that doesn't settle
|
|
30
|
+
* it, with each match described for the agent to pick by index.
|
|
31
|
+
*/
|
|
32
|
+
export declare function pickAmong(matches: Locator, count: number): Promise<{
|
|
33
|
+
index: number;
|
|
34
|
+
why: string;
|
|
35
|
+
} | {
|
|
36
|
+
index: null;
|
|
37
|
+
described: string[];
|
|
38
|
+
}>;
|
|
39
|
+
/** When the element is behind the modal dialog in front, that dialog's title: a click there can't land. */
|
|
40
|
+
export declare function behindModal(el: Locator): Promise<string | null>;
|
|
41
|
+
/** Why a click failed, in a sentence, from Playwright's log of what it tried. */
|
|
42
|
+
export declare function whyNotClicked(e: unknown): string;
|
|
43
|
+
/**
|
|
44
|
+
* Whether what is in front of a control is its own label: a styled radio or checkbox draws its label (or a
|
|
45
|
+
* box inside it) over the real input, and a person clicks that. Clicking the label is then the same click.
|
|
46
|
+
*/
|
|
47
|
+
export declare function coveredByOwnLabel(el: Locator): Promise<boolean>;
|
|
48
|
+
/** A stroke as fractions of the element's box: [x, y] pairs, 0 to 1. */
|
|
49
|
+
export type Stroke = [number, number][];
|
|
50
|
+
/** A signature-like scribble, for a pad that only needs one. */
|
|
51
|
+
export declare const SIGNATURE: Stroke[];
|
|
52
|
+
/** Draws strokes on an element with the pointer, as a finger or a mouse would: down, moves, up. */
|
|
53
|
+
export declare function draw(page: Page, el: Locator, strokes?: Stroke[]): Promise<void>;
|
|
54
|
+
/** Where a drag goes: a point on another element (fractions of its box), or a distance in CSS pixels. */
|
|
55
|
+
export type DragTo = {
|
|
56
|
+
el: Locator;
|
|
57
|
+
at: [number, number];
|
|
58
|
+
} | {
|
|
59
|
+
by: {
|
|
60
|
+
x: number;
|
|
61
|
+
y: number;
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Drags with the pointer, as a person would: press at a point on the element (fractions of its box), move
|
|
66
|
+
* a little first (a drag library starts a drag only once the pointer has moved), then on to the drop in small
|
|
67
|
+
* steps, pause over it (a drop target answers hovering), and let go. Both ends must be on screen.
|
|
68
|
+
*/
|
|
69
|
+
export declare function drag(page: Page, el: Locator, grab: [number, number], to: DragTo): Promise<void>;
|
|
70
|
+
//# sourceMappingURL=sight.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sight.d.ts","sourceRoot":"","sources":["../../src/fleet/sight.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AASrD,MAAM,WAAW,UAAU;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,KAAK,EAAE,OAAO,CAAC;IACf,sDAAsD;IACtD,IAAI,EAAE,MAAM,CAAC;CACd;AAgCD;;;GAGG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC,CAsBnE;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAWzD;AAED,6FAA6F;AAC7F,MAAM,WAAW,MAAM;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,qCAAqC;IACrC,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAmBxD;AAED,iGAAiG;AACjG,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAQ/D;AAYD;;;;;GAKG;AACH,wBAAsB,SAAS,CAC7B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,EAA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