@liyuera/dsh-chrome-browser 0.2.0 → 0.4.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 +270 -20
- package/extension/manifest.json +4 -3
- package/extension/service-worker.js +721 -68
- package/lib/activity.d.ts +65 -0
- package/lib/activity.d.ts.map +1 -0
- package/lib/activity.js +111 -0
- package/lib/activity.js.map +1 -0
- package/lib/backend.d.ts +193 -11
- package/lib/backend.d.ts.map +1 -1
- package/lib/backend.js +344 -39
- package/lib/backend.js.map +1 -1
- package/lib/cdp.d.ts +7 -1
- package/lib/cdp.d.ts.map +1 -1
- package/lib/cdp.js +17 -1
- package/lib/cdp.js.map +1 -1
- package/lib/chrome.d.ts +8 -0
- package/lib/chrome.d.ts.map +1 -1
- package/lib/chrome.js +20 -0
- package/lib/chrome.js.map +1 -1
- package/lib/client/BrowserActivity.d.ts +22 -0
- package/lib/client/BrowserActivity.d.ts.map +1 -0
- package/lib/client/BrowserActivity.js +100 -0
- package/lib/client/BrowserActivity.js.map +1 -0
- package/lib/client/activity.d.ts +27 -0
- package/lib/client/activity.d.ts.map +1 -0
- package/lib/client/activity.js +57 -0
- package/lib/client/activity.js.map +1 -0
- package/lib/client/index.d.ts +4 -6
- package/lib/client/index.d.ts.map +1 -1
- package/lib/client/index.js +13 -19
- package/lib/client/index.js.map +1 -1
- package/lib/client/tab-catalog.d.ts +11 -1
- package/lib/client/tab-catalog.d.ts.map +1 -1
- package/lib/client/tab-catalog.js.map +1 -1
- package/lib/client/tab-source.d.ts +8 -2
- package/lib/client/tab-source.d.ts.map +1 -1
- package/lib/client/tab-source.js.map +1 -1
- package/lib/client.js +177 -13
- package/lib/client.js.map +1 -1
- package/lib/console-events.d.ts +32 -0
- package/lib/console-events.d.ts.map +1 -0
- package/lib/console-events.js +106 -0
- package/lib/console-events.js.map +1 -0
- package/lib/console-log.d.ts +107 -0
- package/lib/console-log.d.ts.map +1 -0
- package/lib/console-log.js +158 -0
- package/lib/console-log.js.map +1 -0
- package/lib/expressions.d.ts +71 -2
- package/lib/expressions.d.ts.map +1 -1
- package/lib/expressions.js +277 -14
- package/lib/expressions.js.map +1 -1
- package/lib/extension-package.d.ts +33 -0
- package/lib/extension-package.d.ts.map +1 -0
- package/lib/extension-package.js +133 -0
- package/lib/extension-package.js.map +1 -0
- package/lib/help.d.ts +89 -0
- package/lib/help.d.ts.map +1 -0
- package/lib/help.js +94 -0
- package/lib/help.js.map +1 -0
- package/lib/index.d.ts +4 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +30 -9
- package/lib/index.js.map +1 -1
- package/lib/presentation.d.ts +130 -0
- package/lib/presentation.d.ts.map +1 -0
- package/lib/presentation.js +361 -0
- package/lib/presentation.js.map +1 -0
- package/lib/routes.d.ts +3 -8
- package/lib/routes.d.ts.map +1 -1
- package/lib/routes.js +38 -99
- package/lib/routes.js.map +1 -1
- package/lib/skill.d.ts +50 -0
- package/lib/skill.d.ts.map +1 -0
- package/lib/skill.js +163 -0
- package/lib/skill.js.map +1 -0
- package/lib/text.d.ts +21 -0
- package/lib/text.d.ts.map +1 -1
- package/lib/text.js +18 -0
- package/lib/text.js.map +1 -1
- package/lib/tools.d.ts +22 -4
- package/lib/tools.d.ts.map +1 -1
- package/lib/tools.js +467 -75
- package/lib/tools.js.map +1 -1
- package/lib/ws.d.ts +9 -2
- package/lib/ws.d.ts.map +1 -1
- package/lib/ws.js +49 -19
- package/lib/ws.js.map +1 -1
- package/package.json +4 -3
- package/lib/bindings.d.ts +0 -23
- package/lib/bindings.d.ts.map +0 -1
- package/lib/bindings.js +0 -49
- package/lib/bindings.js.map +0 -1
- package/lib/client/TabPicker.d.ts +0 -54
- package/lib/client/TabPicker.d.ts.map +0 -1
- package/lib/client/TabPicker.js +0 -329
- package/lib/client/TabPicker.js.map +0 -1
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turning captured DevTools events into console messages.
|
|
3
|
+
*
|
|
4
|
+
* The extension bridge runs the same mapping in `extension/service-worker.js`
|
|
5
|
+
* (`consoleMessageFrom`), because the bridge cannot import host modules: the
|
|
6
|
+
* two copies must stay in step, and tests/console-capture.spec.ts requires them
|
|
7
|
+
* to agree on the same recorded events.
|
|
8
|
+
*
|
|
9
|
+
* The browser reports two families worth keeping: `Runtime.consoleAPICalled`
|
|
10
|
+
* for `console.*` calls the page made, and `Log.entryAdded` for messages the
|
|
11
|
+
* browser itself raises (failed requests, CSP refusals, deprecations) — the
|
|
12
|
+
* second family is invisible to any wrapper around `console`, which is why
|
|
13
|
+
* capture goes through the debugger.
|
|
14
|
+
* @module @liyuera/dsh-chrome-browser/console-events
|
|
15
|
+
*/
|
|
16
|
+
/** Cap one rendered argument list; the buffer caps again per message. */
|
|
17
|
+
const MAX_ARG_CHARS = 2048;
|
|
18
|
+
/** One value in a `console.*` argument list, rendered as the console shows it. */
|
|
19
|
+
function renderRemote(value) {
|
|
20
|
+
if (typeof value !== 'object' || value === null)
|
|
21
|
+
return String(value);
|
|
22
|
+
const remote = value;
|
|
23
|
+
const type = typeof remote.type === 'string' ? remote.type : 'object';
|
|
24
|
+
if (type === 'undefined')
|
|
25
|
+
return 'undefined';
|
|
26
|
+
// A primitive carries its value directly; a string renders unquoted, the way
|
|
27
|
+
// the console shows it.
|
|
28
|
+
if (remote.value !== undefined && remote.value !== null)
|
|
29
|
+
return String(remote.value);
|
|
30
|
+
if (remote.value === null)
|
|
31
|
+
return 'null';
|
|
32
|
+
const preview = typeof remote.preview === 'object' && remote.preview !== null
|
|
33
|
+
? remote.preview
|
|
34
|
+
: undefined;
|
|
35
|
+
if (preview !== undefined) {
|
|
36
|
+
const properties = Array.isArray(preview.properties) ? preview.properties : [];
|
|
37
|
+
const rendered = properties.map((property) => {
|
|
38
|
+
if (typeof property !== 'object' || property === null)
|
|
39
|
+
return '?';
|
|
40
|
+
const entry = property;
|
|
41
|
+
const name = typeof entry.name === 'string' ? entry.name : '?';
|
|
42
|
+
const shown = entry.value !== undefined ? String(entry.value) : String(entry.type ?? '?');
|
|
43
|
+
return `${name}: ${shown}`;
|
|
44
|
+
});
|
|
45
|
+
const head = typeof preview.description === 'string' && preview.description !== '' ? preview.description : '';
|
|
46
|
+
const more = preview.overflow === true ? ', …' : '';
|
|
47
|
+
return `${head}{${rendered.join(', ')}${more}}`;
|
|
48
|
+
}
|
|
49
|
+
if (typeof remote.description === 'string' && remote.description !== '')
|
|
50
|
+
return remote.description;
|
|
51
|
+
return type;
|
|
52
|
+
}
|
|
53
|
+
/** `url:line` from a CDP stack trace, when it carries a usable frame. */
|
|
54
|
+
function sourceFromStack(stackTrace) {
|
|
55
|
+
if (typeof stackTrace !== 'object' || stackTrace === null)
|
|
56
|
+
return undefined;
|
|
57
|
+
const frames = stackTrace.callFrames;
|
|
58
|
+
if (!Array.isArray(frames))
|
|
59
|
+
return undefined;
|
|
60
|
+
const first = frames[0];
|
|
61
|
+
if (typeof first !== 'object' || first === null)
|
|
62
|
+
return undefined;
|
|
63
|
+
const frame = first;
|
|
64
|
+
const url = typeof frame.url === 'string' ? frame.url : '';
|
|
65
|
+
const line = typeof frame.lineNumber === 'number' ? frame.lineNumber + 1 : undefined;
|
|
66
|
+
if (url === '')
|
|
67
|
+
return undefined;
|
|
68
|
+
return line === undefined ? url : `${url}:${line}`;
|
|
69
|
+
}
|
|
70
|
+
/** `url:line` from a `Log` entry, when it carries one. */
|
|
71
|
+
function sourceFromEntry(entry) {
|
|
72
|
+
const url = typeof entry.url === 'string' ? entry.url : '';
|
|
73
|
+
if (url === '')
|
|
74
|
+
return undefined;
|
|
75
|
+
const line = typeof entry.lineNumber === 'number' ? entry.lineNumber : undefined;
|
|
76
|
+
return line === undefined ? url : `${url}:${line}`;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Map one captured DevTools event onto a console message.
|
|
80
|
+
* @param method - the CDP event name.
|
|
81
|
+
* @param params - the event payload.
|
|
82
|
+
* @returns the message, or undefined for an event this plugin does not keep.
|
|
83
|
+
*/
|
|
84
|
+
export function consoleMessageFrom(method, params) {
|
|
85
|
+
if (method === 'Runtime.consoleAPICalled') {
|
|
86
|
+
const args = Array.isArray(params.args) ? params.args : [];
|
|
87
|
+
const text = args.map(renderRemote).join(' ').slice(0, MAX_ARG_CHARS);
|
|
88
|
+
const level = typeof params.type === 'string' ? params.type : 'log';
|
|
89
|
+
const source = sourceFromStack(params.stackTrace);
|
|
90
|
+
return source === undefined ? { level, text } : { level, text, source };
|
|
91
|
+
}
|
|
92
|
+
if (method === 'Log.entryAdded') {
|
|
93
|
+
const raw = params.entry;
|
|
94
|
+
if (typeof raw !== 'object' || raw === null)
|
|
95
|
+
return undefined;
|
|
96
|
+
const entry = raw;
|
|
97
|
+
const text = typeof entry.text === 'string' ? entry.text : '';
|
|
98
|
+
if (text === '')
|
|
99
|
+
return undefined;
|
|
100
|
+
const level = typeof entry.level === 'string' ? entry.level : 'info';
|
|
101
|
+
const source = sourceFromEntry(entry);
|
|
102
|
+
return source === undefined ? { level, text } : { level, text, source };
|
|
103
|
+
}
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=console-events.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-events.js","sourceRoot":"","sources":["../src/console-events.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAYH,yEAAyE;AACzE,MAAM,aAAa,GAAG,IAAI,CAAA;AAE1B,kFAAkF;AAClF,SAAS,YAAY,CAAC,KAAc;IAClC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAA;IACrE,MAAM,MAAM,GAAG,KAAgC,CAAA;IAC/C,MAAM,IAAI,GAAG,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAA;IACrE,I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MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACzE,CAAC;IACD,IAAI,MAAM,KAAK,gBAAgB,EAAE,CAAC;QAChC,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAA;QACxB,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;YAAE,OAAO,SAAS,CAAA;QAC7D,MAAM,KAAK,GAAG,GAA8B,CAAA;QAC5C,MAAM,IAAI,GAAG,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;QAC7D,IAAI,IAAI,KAAK,EAAE;YAAE,OAAO,SAAS,CAAA;QACjC,MAAM,KAAK,GAAG,OAAO,KAAK,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAA;QACpE,MAAM,MAAM,GAAG,eAAe,CAAC,KAAK,CAAC,CAAA;QACrC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,CAAA;IACzE,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded console capture, one buffer per tab.
|
|
3
|
+
*
|
|
4
|
+
* The bounds are count and bytes, never time: a page that logs in a loop can
|
|
5
|
+
* produce more text in one second than a quiet page produces in an hour, so a
|
|
6
|
+
* retention window cannot bound memory. What bounds it is a fixed number of
|
|
7
|
+
* entries and a fixed text budget per tab, plus a fixed number of captured tabs
|
|
8
|
+
* — together a constant ceiling that does not grow with how long the plugin
|
|
9
|
+
* runs.
|
|
10
|
+
*
|
|
11
|
+
* Nothing here is durable. Entries live in the host process for as long as the
|
|
12
|
+
* tab is captured and are never written to the session log; only what a caller
|
|
13
|
+
* reads back enters a transcript.
|
|
14
|
+
* @module @liyuera/dsh-chrome-browser/console-log
|
|
15
|
+
*/
|
|
16
|
+
/** Entries one tab keeps; the oldest are dropped past this. */
|
|
17
|
+
export declare const MAX_ENTRIES = 200;
|
|
18
|
+
/**
|
|
19
|
+
* Text one tab keeps across all its entries, in UTF-16 code units. V8 stores an
|
|
20
|
+
* all-Latin-1 string one byte per unit and a wider string two, so a tab holds
|
|
21
|
+
* 256 KB of ASCII or 512 KB of CJK — the ceiling is this constant times
|
|
22
|
+
* {@link MAX_TABS}, and it does not depend on how long the plugin runs.
|
|
23
|
+
*/
|
|
24
|
+
export declare const MAX_CHARS: number;
|
|
25
|
+
/** Text one entry keeps; a longer message keeps its head plus a marker. */
|
|
26
|
+
export declare const MAX_ENTRY_CHARS = 4096;
|
|
27
|
+
/** Tabs captured at once; tracking one more releases the least recently used. */
|
|
28
|
+
export declare const MAX_TABS = 5;
|
|
29
|
+
/** One captured console message. */
|
|
30
|
+
export interface ConsoleEntry {
|
|
31
|
+
/** Monotonic per tab; `since` cursors compare against it. */
|
|
32
|
+
readonly seq: number;
|
|
33
|
+
/** Epoch milliseconds when the host recorded it. */
|
|
34
|
+
readonly at: number;
|
|
35
|
+
/** Level the page reported (`log`, `warning`, `error`, …). */
|
|
36
|
+
readonly level: string;
|
|
37
|
+
/** Message text, already capped to {@link MAX_ENTRY_CHARS}. */
|
|
38
|
+
readonly text: string;
|
|
39
|
+
/** Call site the browser reported, when it reported one. */
|
|
40
|
+
readonly source?: string;
|
|
41
|
+
}
|
|
42
|
+
/** One tab's retained window, plus what fell out of it. */
|
|
43
|
+
export interface ConsolePage {
|
|
44
|
+
/** Entries after the cursor, oldest first. */
|
|
45
|
+
readonly entries: readonly ConsoleEntry[];
|
|
46
|
+
/** Entries currently retained for the tab. */
|
|
47
|
+
readonly retained: number;
|
|
48
|
+
/** Entries evicted since capture started on this tab. */
|
|
49
|
+
readonly dropped: number;
|
|
50
|
+
/** Cursor to pass as `since` next time; equals the newest returned `seq`. */
|
|
51
|
+
readonly cursor: number;
|
|
52
|
+
}
|
|
53
|
+
/** Cap one message, keeping its head so an oversized line cannot clear the buffer. */
|
|
54
|
+
export declare function capMessage(text: string): string;
|
|
55
|
+
/**
|
|
56
|
+
* A per-tab console window with fixed memory bounds. Every operation is O(1)
|
|
57
|
+
* amortized: eviction pops from the front, and the retained character count is
|
|
58
|
+
* maintained on append rather than recomputed.
|
|
59
|
+
*/
|
|
60
|
+
export declare class ConsoleLog {
|
|
61
|
+
private readonly buffers;
|
|
62
|
+
private clock;
|
|
63
|
+
/** Whether one tab is currently captured. */
|
|
64
|
+
tracks(tabId: string): boolean;
|
|
65
|
+
/** Captured tab ids, most recently used first. */
|
|
66
|
+
tracked(): string[];
|
|
67
|
+
/**
|
|
68
|
+
* Begin capturing one tab. Idempotent: a tab already captured keeps its
|
|
69
|
+
* window, which matters when a reconnecting bridge re-arms capture. Tracking
|
|
70
|
+
* past {@link MAX_TABS} releases the least recently used tab.
|
|
71
|
+
* @param tabId - the tab to capture.
|
|
72
|
+
* @returns the tab id released to stay within the cap, when one was.
|
|
73
|
+
*/
|
|
74
|
+
track(tabId: string): string | undefined;
|
|
75
|
+
/** Stop capturing one tab and drop everything it held. */
|
|
76
|
+
release(tabId: string): void;
|
|
77
|
+
/** Stop capturing every tab. */
|
|
78
|
+
releaseAll(): void;
|
|
79
|
+
/**
|
|
80
|
+
* Record one message on a captured tab. A tab that is not captured is
|
|
81
|
+
* ignored, so a late event from a released tab cannot resurrect its buffer.
|
|
82
|
+
* @param tabId - the tab the message came from.
|
|
83
|
+
* @param entry - level, text and optional call site.
|
|
84
|
+
* @returns whether the entry was retained.
|
|
85
|
+
*/
|
|
86
|
+
append(tabId: string, entry: Omit<ConsoleEntry, 'seq' | 'at'> & {
|
|
87
|
+
at?: number;
|
|
88
|
+
}): boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Read the window a caller has not seen yet.
|
|
91
|
+
* @param tabId - the captured tab.
|
|
92
|
+
* @param options - `since` is an exclusive cursor (0 starts at the beginning);
|
|
93
|
+
* `limit` keeps the most recent entries of the matching set.
|
|
94
|
+
* @returns the page, or undefined when the tab is not captured.
|
|
95
|
+
*/
|
|
96
|
+
read(tabId: string, options?: {
|
|
97
|
+
since?: number;
|
|
98
|
+
limit?: number;
|
|
99
|
+
}): ConsolePage | undefined;
|
|
100
|
+
/** Drop one tab's entries but keep capturing it; the cursor continues from the newest seq. */
|
|
101
|
+
clear(tabId: string): boolean;
|
|
102
|
+
/** Retained text across every captured tab, in code units (observability for tests). */
|
|
103
|
+
get retainedChars(): number;
|
|
104
|
+
/** Drop the oldest entries until both the count and the text budget hold. */
|
|
105
|
+
private evict;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=console-log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-log.d.ts","sourceRoot":"","sources":["../src/console-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,+DAA+D;AAC/D,eAAO,MAAM,WAAW,MAAM,CAAA;AAE9B;;;;;GAKG;AACH,eAAO,MAAM,SAAS,QAAa,CAAA;AAEnC,2EAA2E;AAC3E,eAAO,MAAM,eAAe,OAAO,CAAA;AAEnC,iFAAiF;AACjF,eAAO,MAAM,QAAQ,IAAI,CAAA;AAKzB,oCAAoC;AACpC,MAAM,WAAW,YAAY;IAC3B,6DAA6D;IAC7D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,oDAAoD;IACpD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAA;IACnB,8DAA8D;IAC9D,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,+DAA+D;IAC/D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,4DAA4D;IAC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AM,GAAG,OAAO;IAQ7B,wFAAwF;IACxF,IAAI,aAAa,IAAI,MAAM,CAI1B;IAED,6EAA6E;IAC7E,OAAO,CAAC,KAAK;CAQd"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bounded console capture, one buffer per tab.
|
|
3
|
+
*
|
|
4
|
+
* The bounds are count and bytes, never time: a page that logs in a loop can
|
|
5
|
+
* produce more text in one second than a quiet page produces in an hour, so a
|
|
6
|
+
* retention window cannot bound memory. What bounds it is a fixed number of
|
|
7
|
+
* entries and a fixed text budget per tab, plus a fixed number of captured tabs
|
|
8
|
+
* — together a constant ceiling that does not grow with how long the plugin
|
|
9
|
+
* runs.
|
|
10
|
+
*
|
|
11
|
+
* Nothing here is durable. Entries live in the host process for as long as the
|
|
12
|
+
* tab is captured and are never written to the session log; only what a caller
|
|
13
|
+
* reads back enters a transcript.
|
|
14
|
+
* @module @liyuera/dsh-chrome-browser/console-log
|
|
15
|
+
*/
|
|
16
|
+
/** Entries one tab keeps; the oldest are dropped past this. */
|
|
17
|
+
export const MAX_ENTRIES = 200;
|
|
18
|
+
/**
|
|
19
|
+
* Text one tab keeps across all its entries, in UTF-16 code units. V8 stores an
|
|
20
|
+
* all-Latin-1 string one byte per unit and a wider string two, so a tab holds
|
|
21
|
+
* 256 KB of ASCII or 512 KB of CJK — the ceiling is this constant times
|
|
22
|
+
* {@link MAX_TABS}, and it does not depend on how long the plugin runs.
|
|
23
|
+
*/
|
|
24
|
+
export const MAX_CHARS = 256 * 1024;
|
|
25
|
+
/** Text one entry keeps; a longer message keeps its head plus a marker. */
|
|
26
|
+
export const MAX_ENTRY_CHARS = 4096;
|
|
27
|
+
/** Tabs captured at once; tracking one more releases the least recently used. */
|
|
28
|
+
export const MAX_TABS = 5;
|
|
29
|
+
/** Marker appended to a message the per-entry cap cut short. */
|
|
30
|
+
const TRUNCATED = '…[truncated]';
|
|
31
|
+
/** Cap one message, keeping its head so an oversized line cannot clear the buffer. */
|
|
32
|
+
export function capMessage(text) {
|
|
33
|
+
return text.length <= MAX_ENTRY_CHARS ? text : `${text.slice(0, MAX_ENTRY_CHARS)}${TRUNCATED}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* A per-tab console window with fixed memory bounds. Every operation is O(1)
|
|
37
|
+
* amortized: eviction pops from the front, and the retained character count is
|
|
38
|
+
* maintained on append rather than recomputed.
|
|
39
|
+
*/
|
|
40
|
+
export class ConsoleLog {
|
|
41
|
+
buffers = new Map();
|
|
42
|
+
clock = 0;
|
|
43
|
+
/** Whether one tab is currently captured. */
|
|
44
|
+
tracks(tabId) {
|
|
45
|
+
return this.buffers.has(tabId);
|
|
46
|
+
}
|
|
47
|
+
/** Captured tab ids, most recently used first. */
|
|
48
|
+
tracked() {
|
|
49
|
+
return [...this.buffers.entries()]
|
|
50
|
+
.sort((left, right) => right[1].used - left[1].used)
|
|
51
|
+
.map(([tabId]) => tabId);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Begin capturing one tab. Idempotent: a tab already captured keeps its
|
|
55
|
+
* window, which matters when a reconnecting bridge re-arms capture. Tracking
|
|
56
|
+
* past {@link MAX_TABS} releases the least recently used tab.
|
|
57
|
+
* @param tabId - the tab to capture.
|
|
58
|
+
* @returns the tab id released to stay within the cap, when one was.
|
|
59
|
+
*/
|
|
60
|
+
track(tabId) {
|
|
61
|
+
const existing = this.buffers.get(tabId);
|
|
62
|
+
if (existing !== undefined) {
|
|
63
|
+
existing.used = ++this.clock;
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
let released;
|
|
67
|
+
if (this.buffers.size >= MAX_TABS) {
|
|
68
|
+
const oldest = this.tracked().at(-1);
|
|
69
|
+
if (oldest !== undefined) {
|
|
70
|
+
this.buffers.delete(oldest);
|
|
71
|
+
released = oldest;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
this.buffers.set(tabId, { entries: [], chars: 0, seq: 0, dropped: 0, used: ++this.clock });
|
|
75
|
+
return released;
|
|
76
|
+
}
|
|
77
|
+
/** Stop capturing one tab and drop everything it held. */
|
|
78
|
+
release(tabId) {
|
|
79
|
+
this.buffers.delete(tabId);
|
|
80
|
+
}
|
|
81
|
+
/** Stop capturing every tab. */
|
|
82
|
+
releaseAll() {
|
|
83
|
+
this.buffers.clear();
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Record one message on a captured tab. A tab that is not captured is
|
|
87
|
+
* ignored, so a late event from a released tab cannot resurrect its buffer.
|
|
88
|
+
* @param tabId - the tab the message came from.
|
|
89
|
+
* @param entry - level, text and optional call site.
|
|
90
|
+
* @returns whether the entry was retained.
|
|
91
|
+
*/
|
|
92
|
+
append(tabId, entry) {
|
|
93
|
+
const buffer = this.buffers.get(tabId);
|
|
94
|
+
if (buffer === undefined)
|
|
95
|
+
return false;
|
|
96
|
+
const text = capMessage(entry.text);
|
|
97
|
+
buffer.entries.push({
|
|
98
|
+
seq: ++buffer.seq,
|
|
99
|
+
at: entry.at ?? Date.now(),
|
|
100
|
+
level: entry.level,
|
|
101
|
+
text,
|
|
102
|
+
...(entry.source === undefined ? {} : { source: entry.source }),
|
|
103
|
+
});
|
|
104
|
+
buffer.chars += text.length;
|
|
105
|
+
buffer.used = ++this.clock;
|
|
106
|
+
this.evict(buffer);
|
|
107
|
+
return true;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Read the window a caller has not seen yet.
|
|
111
|
+
* @param tabId - the captured tab.
|
|
112
|
+
* @param options - `since` is an exclusive cursor (0 starts at the beginning);
|
|
113
|
+
* `limit` keeps the most recent entries of the matching set.
|
|
114
|
+
* @returns the page, or undefined when the tab is not captured.
|
|
115
|
+
*/
|
|
116
|
+
read(tabId, options = {}) {
|
|
117
|
+
const buffer = this.buffers.get(tabId);
|
|
118
|
+
if (buffer === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
const since = options.since ?? 0;
|
|
121
|
+
const matching = buffer.entries.filter(entry => entry.seq > since);
|
|
122
|
+
const limit = options.limit ?? MAX_ENTRIES;
|
|
123
|
+
const entries = limit >= matching.length ? matching : matching.slice(-limit);
|
|
124
|
+
return {
|
|
125
|
+
entries,
|
|
126
|
+
retained: buffer.entries.length,
|
|
127
|
+
dropped: buffer.dropped,
|
|
128
|
+
cursor: entries.at(-1)?.seq ?? since,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/** Drop one tab's entries but keep capturing it; the cursor continues from the newest seq. */
|
|
132
|
+
clear(tabId) {
|
|
133
|
+
const buffer = this.buffers.get(tabId);
|
|
134
|
+
if (buffer === undefined)
|
|
135
|
+
return false;
|
|
136
|
+
buffer.entries = [];
|
|
137
|
+
buffer.chars = 0;
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
/** Retained text across every captured tab, in code units (observability for tests). */
|
|
141
|
+
get retainedChars() {
|
|
142
|
+
let total = 0;
|
|
143
|
+
for (const buffer of this.buffers.values())
|
|
144
|
+
total += buffer.chars;
|
|
145
|
+
return total;
|
|
146
|
+
}
|
|
147
|
+
/** Drop the oldest entries until both the count and the text budget hold. */
|
|
148
|
+
evict(buffer) {
|
|
149
|
+
while (buffer.entries.length > MAX_ENTRIES || buffer.chars > MAX_CHARS) {
|
|
150
|
+
const dropped = buffer.entries.shift();
|
|
151
|
+
if (dropped === undefined)
|
|
152
|
+
return;
|
|
153
|
+
buffer.chars -= dropped.text.length;
|
|
154
|
+
buffer.dropped += 1;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=console-log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"console-log.js","sourceRoot":"","sources":["../src/console-log.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,CAAA;AAE9B;;;;;GAKG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,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MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACtC,IAAI,MAAM,KAAK,SAAS;YAAE,OAAO,KAAK,CAAA;QACtC,MAAM,CAAC,OAAO,GAAG,EAAE,CAAA;QACnB,MAAM,CAAC,KAAK,GAAG,CAAC,CAAA;QAChB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,wFAAwF;IACxF,IAAI,aAAa;QACf,IAAI,KAAK,GAAG,CAAC,CAAA;QACb,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE;YAAE,KAAK,IAAI,MAAM,CAAC,KAAK,CAAA;QACjE,OAAO,KAAK,CAAA;IACd,CAAC;IAED,6EAA6E;IACrE,KAAK,CAAC,MAAc;QAC1B,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,GAAG,WAAW,IAAI,MAAM,CAAC,KAAK,GAAG,SAAS,EAAE,CAAC;YACvE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAA;YACtC,IAAI,OAAO,KAAK,SAAS;gBAAE,OAAM;YACjC,MAAM,CAAC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAA;YACnC,MAAM,CAAC,OAAO,IAAI,CAAC,CAAA;QACrB,CAAC;IACH,CAAC;CACF"}
|
package/lib/expressions.d.ts
CHANGED
|
@@ -4,6 +4,54 @@
|
|
|
4
4
|
* serialization and cannot leak page globals into the harness.
|
|
5
5
|
* @module @liyuera/dsh-chrome-browser/expressions
|
|
6
6
|
*/
|
|
7
|
+
/**
|
|
8
|
+
* Press expression: dispatch one key on a matched element, or on whatever
|
|
9
|
+
* currently has focus.
|
|
10
|
+
*
|
|
11
|
+
* Synthetic key events do not trigger the browser's own default actions, so
|
|
12
|
+
* `Enter` in a form would type nothing and submit nothing. The expression
|
|
13
|
+
* therefore submits the owning form explicitly and reports that it did, rather
|
|
14
|
+
* than leaving the caller to guess why nothing happened.
|
|
15
|
+
* @param key - the `KeyboardEvent.key` value, e.g. `Enter` or `ArrowDown`.
|
|
16
|
+
* @param selector - element to focus first; omit to press on the focused element.
|
|
17
|
+
* @returns a self-contained expression evaluating to `{ found, pressed, submitted }`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function pressExpression(key: string, selector?: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* Select expression: set a `<select>`'s value and fire the events a controlled
|
|
22
|
+
* component listens for, through the prototype setter so frameworks that patch
|
|
23
|
+
* the instance still see the change.
|
|
24
|
+
*
|
|
25
|
+
* A value with no matching option leaves the select unchanged; the result says
|
|
26
|
+
* so and lists what was available instead of reporting a success the page never
|
|
27
|
+
* saw.
|
|
28
|
+
* @param selector - CSS selector for the `<select>`.
|
|
29
|
+
* @param value - the option value to select.
|
|
30
|
+
* @returns a self-contained expression evaluating to the selection outcome.
|
|
31
|
+
*/
|
|
32
|
+
export declare function selectExpression(selector: string, value: string): string;
|
|
33
|
+
/** Element conditions `chrome_wait` can wait for. */
|
|
34
|
+
export type WaitState = 'attached' | 'detached' | 'visible' | 'hidden';
|
|
35
|
+
/**
|
|
36
|
+
* Poll expression for one wait condition: does the selector currently satisfy
|
|
37
|
+
* `state`? Resolved fresh on every poll, because the page changes between them.
|
|
38
|
+
* @param selector - CSS selector to test.
|
|
39
|
+
* @param state - the condition to test for.
|
|
40
|
+
* @returns a self-contained expression evaluating to a boolean.
|
|
41
|
+
*/
|
|
42
|
+
export declare function waitExpression(selector: string, state: WaitState): string;
|
|
43
|
+
/**
|
|
44
|
+
* Hover expression: dispatch the pointer events a hover-driven menu listens for
|
|
45
|
+
* on the first match.
|
|
46
|
+
*
|
|
47
|
+
* These are synthetic: they reach listeners the page attached, but they do not
|
|
48
|
+
* set the browser's own hover state, so a control revealed purely by a CSS
|
|
49
|
+
* `:hover` rule will not appear. The alternative — real pointer input — is not
|
|
50
|
+
* available on the extension bridge, so both backends behave the same.
|
|
51
|
+
* @param selector - CSS selector to hover.
|
|
52
|
+
* @returns a self-contained expression evaluating to `{ matched, hovered }`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function hoverExpression(selector: string): string;
|
|
7
55
|
/** Live page-facts expression: title, url, visible text, optional HTML. */
|
|
8
56
|
export declare function readPageExpression(includeHtml: boolean): string;
|
|
9
57
|
/** Viewport dimensions expression (screenshot metadata). */
|
|
@@ -11,10 +59,31 @@ export declare function viewportExpression(): string;
|
|
|
11
59
|
/** Document readiness poll expression (navigation wait). */
|
|
12
60
|
export declare function readyStateExpression(): string;
|
|
13
61
|
/**
|
|
14
|
-
* Click expression. Returns
|
|
15
|
-
*
|
|
62
|
+
* Click expression. Returns one outcome per call: how many elements the
|
|
63
|
+
* selector matched, how many received a dispatched click, and why the rest did
|
|
64
|
+
* not or may not have taken effect. `all` clicks every match, otherwise only
|
|
65
|
+
* the first.
|
|
66
|
+
* @param selector - CSS selector to resolve.
|
|
67
|
+
* @param all - whether to click every match instead of the first.
|
|
68
|
+
* @returns a self-contained expression evaluating to the click outcome.
|
|
16
69
|
*/
|
|
17
70
|
export declare function clickExpression(selector: string, all: boolean): string;
|
|
71
|
+
/** Elements the interactive inventory considers actionable. */
|
|
72
|
+
export declare const INTERACTIVE_SELECTOR: string;
|
|
73
|
+
/** Elements one inventory returns; a longer page is reported as capped. */
|
|
74
|
+
export declare const INVENTORY_LIMIT = 150;
|
|
75
|
+
/**
|
|
76
|
+
* Interactive-element inventory expression: what a reader can act on, with the
|
|
77
|
+
* selector to act on it, instead of the page's prose. Shares the click probe
|
|
78
|
+
* with {@link clickExpression}, so `covered` here means the same thing it means
|
|
79
|
+
* in a click result.
|
|
80
|
+
*
|
|
81
|
+
* The extension bridge runs the same inventory in
|
|
82
|
+
* `extension/service-worker.js` (`interactiveInventory`), because it cannot
|
|
83
|
+
* import host modules; tests/inventory.spec.ts requires the two to agree.
|
|
84
|
+
* @returns a self-contained expression evaluating to `{ matched, items }`.
|
|
85
|
+
*/
|
|
86
|
+
export declare function inventoryExpression(): string;
|
|
18
87
|
/**
|
|
19
88
|
* Focus-only expression for typing without replacing existing content: focuses
|
|
20
89
|
* the matched element and leaves its selection untouched. Returns whether a
|
package/lib/expressions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../src/expressions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"expressions.d.ts","sourceRoot":"","sources":["../src/expressions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA4BH;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAuBtE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAwBxE;AAED,qDAAqD;AACrD,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAA;AAEtE;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,GAAG,MAAM,CAoBzE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAsBxD;AAED,2EAA2E;AAC3E,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,OAAO,GAAG,MAAM,CAQ/D;AAED,4DAA4D;AAC5D,wBAAgB,kBAAkB,IAAI,MAAM,CAE3C;AAED,4DAA4D;AAC5D,wBAAgB,oBAAoB,IAAI,MAAM,CAE7C;AA4BD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,GAAG,MAAM,CAkBtE;AAED,+DAA+D;AAC/D,eAAO,MAAM,oBAAoB,QACsF,CAAA;AAEvH,2EAA2E;A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