@webhands/core 0.4.0 → 0.6.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 +69 -6
- package/dist/errors.d.ts +112 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +121 -0
- package/dist/errors.js.map +1 -1
- package/dist/hand-host.d.ts +198 -5
- package/dist/hand-host.d.ts.map +1 -1
- package/dist/hand-host.js +664 -21
- package/dist/hand-host.js.map +1 -1
- package/dist/index.d.ts +5 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/playwright-attach-transport.d.ts +8 -1
- package/dist/playwright-attach-transport.d.ts.map +1 -1
- package/dist/playwright-attach-transport.js +19 -4
- package/dist/playwright-attach-transport.js.map +1 -1
- package/dist/playwright-launch-transport.d.ts +23 -0
- package/dist/playwright-launch-transport.d.ts.map +1 -1
- package/dist/playwright-launch-transport.js +40 -6
- package/dist/playwright-launch-transport.js.map +1 -1
- package/dist/profile-location.d.ts +19 -0
- package/dist/profile-location.d.ts.map +1 -1
- package/dist/profile-location.js +21 -0
- package/dist/profile-location.js.map +1 -1
- package/dist/seam.d.ts +501 -7
- package/dist/seam.d.ts.map +1 -1
- package/dist/seam.js +31 -0
- package/dist/seam.js.map +1 -1
- package/dist/session-rpc.d.ts +63 -1
- package/dist/session-rpc.d.ts.map +1 -1
- package/dist/session-rpc.js +174 -11
- package/dist/session-rpc.js.map +1 -1
- package/dist/socks-proxy.d.ts +61 -0
- package/dist/socks-proxy.d.ts.map +1 -0
- package/dist/socks-proxy.js +84 -0
- package/dist/socks-proxy.js.map +1 -0
- package/dist/stub-transport.d.ts.map +1 -1
- package/dist/stub-transport.js +74 -6
- package/dist/stub-transport.js.map +1 -1
- package/dist/test-fixtures/fixture-pages.d.ts.map +1 -1
- package/dist/test-fixtures/fixture-pages.js +994 -0
- package/dist/test-fixtures/fixture-pages.js.map +1 -1
- package/dist/test-fixtures/fixture-server.d.ts.map +1 -1
- package/dist/test-fixtures/fixture-server.js +33 -3
- package/dist/test-fixtures/fixture-server.js.map +1 -1
- package/package.json +1 -1
- package/src/errors.ts +164 -1
- package/src/hand-host.ts +797 -21
- package/src/index.ts +27 -1
- package/src/playwright-attach-transport.ts +25 -3
- package/src/playwright-launch-transport.ts +63 -4
- package/src/profile-location.ts +25 -0
- package/src/seam.ts +535 -7
- package/src/session-rpc.ts +276 -14
- package/src/socks-proxy.ts +127 -0
- package/src/stub-transport.ts +83 -6
- package/src/test-fixtures/fixture-pages.ts +1010 -0
- package/src/test-fixtures/fixture-server.ts +32 -3
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import {createServer, type Server} from 'node:http';
|
|
2
2
|
import {FIXTURE_PAGES} from './fixture-pages.js';
|
|
3
3
|
|
|
4
|
+
/** Largest artificial response delay a fixture request may ask for (a guard so
|
|
5
|
+
* a stray `?delayMs=` can never hang the suite). */
|
|
6
|
+
const MAX_DELAY_MS = 5_000;
|
|
7
|
+
|
|
8
|
+
/** Parse `?delayMs=N` from a request URL, clamped to `[0, MAX_DELAY_MS]`. */
|
|
9
|
+
function parseDelayMs(reqUrl: string): number {
|
|
10
|
+
const q = reqUrl.indexOf('?');
|
|
11
|
+
if (q === -1) return 0;
|
|
12
|
+
const raw = new URLSearchParams(reqUrl.slice(q + 1)).get('delayMs');
|
|
13
|
+
const n = raw === null ? 0 : Number.parseInt(raw, 10);
|
|
14
|
+
if (!Number.isFinite(n) || n <= 0) return 0;
|
|
15
|
+
return Math.min(n, MAX_DELAY_MS);
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
/** A running fixture server, with the base URL to point a browser at. */
|
|
5
19
|
export interface FixtureServer {
|
|
6
20
|
/** The base URL, e.g. `http://127.0.0.1:52831`. */
|
|
@@ -21,7 +35,8 @@ export interface FixtureServer {
|
|
|
21
35
|
*/
|
|
22
36
|
export async function startFixtureServer(port = 0): Promise<FixtureServer> {
|
|
23
37
|
const server: Server = createServer((req, res) => {
|
|
24
|
-
const
|
|
38
|
+
const reqUrl = req.url ?? '/';
|
|
39
|
+
const rawPath = reqUrl.split('?')[0];
|
|
25
40
|
const key = rawPath === '/' ? 'index.html' : rawPath.replace(/^\/+/, '');
|
|
26
41
|
const body = FIXTURE_PAGES[key];
|
|
27
42
|
if (body === undefined) {
|
|
@@ -29,8 +44,22 @@ export async function startFixtureServer(port = 0): Promise<FixtureServer> {
|
|
|
29
44
|
res.end('not found');
|
|
30
45
|
return;
|
|
31
46
|
}
|
|
32
|
-
|
|
33
|
-
|
|
47
|
+
// A `?delayMs=N` query holds the RESPONSE back by N ms before sending the
|
|
48
|
+
// (otherwise normal) page. This makes a slow NAVIGATION deterministic: a
|
|
49
|
+
// click that submits to `index.html?delayMs=1500` performs instantly but
|
|
50
|
+
// the navigation only commits ~1.5s later, the case the `click` verb must
|
|
51
|
+
// not mistake for a non-actionable element (it auto-waits for navigation
|
|
52
|
+
// only when not told otherwise). Capped so a bad value cannot hang a test.
|
|
53
|
+
const delayMs = parseDelayMs(reqUrl);
|
|
54
|
+
const send = () => {
|
|
55
|
+
res.writeHead(200, {'content-type': 'text/html; charset=utf-8'});
|
|
56
|
+
res.end(body);
|
|
57
|
+
};
|
|
58
|
+
if (delayMs > 0) {
|
|
59
|
+
setTimeout(send, delayMs);
|
|
60
|
+
} else {
|
|
61
|
+
send();
|
|
62
|
+
}
|
|
34
63
|
});
|
|
35
64
|
|
|
36
65
|
await new Promise<void>((resolve) =>
|