deictic 0.2.0 → 0.3.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/API.md +303 -0
- package/README.md +56 -127
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/index.js +117 -7
- package/dist/client/index.js.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/logs/client.d.ts +4 -0
- package/dist/logs/client.d.ts.map +1 -0
- package/dist/logs/client.js +16 -0
- package/dist/logs/client.js.map +1 -0
- package/dist/logs/index.d.ts +18 -0
- package/dist/logs/index.d.ts.map +1 -0
- package/dist/logs/index.js +21 -0
- package/dist/logs/index.js.map +1 -0
- package/dist/network/client.d.ts +4 -0
- package/dist/network/client.d.ts.map +1 -0
- package/dist/network/client.js +29 -0
- package/dist/network/client.js.map +1 -0
- package/dist/network/index.d.ts +2 -0
- package/dist/network/index.js +39 -0
- package/dist/network/index.js.map +1 -0
- package/dist/recommended/index.d.ts +13 -3
- package/dist/recommended/index.d.ts.map +1 -1
- package/dist/recommended/index.js +8 -1
- package/dist/recommended/index.js.map +1 -1
- package/dist/recordings/client.d.ts +1 -1
- package/dist/recordings/client.d.ts.map +1 -1
- package/dist/recordings/client.js +175 -46
- package/dist/recordings/client.js.map +1 -1
- package/dist/recordings/index.d.ts +2 -2
- package/dist/screenshots/client.d.ts +6 -0
- package/dist/screenshots/client.d.ts.map +1 -1
- package/dist/screenshots/client.js +34 -2
- package/dist/screenshots/client.js.map +1 -1
- package/dist/screenshots/dom.d.ts.map +1 -1
- package/dist/screenshots/dom.js +1 -28
- package/dist/screenshots/dom.js.map +1 -1
- package/dist/screenshots/index.js.map +1 -1
- package/dist/screenshots/rrweb.d.ts +1 -1
- package/dist/screenshots/rrweb.js +5 -1
- package/dist/screenshots/rrweb.js.map +1 -1
- package/dist/shared/index.d.ts +14 -2
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index2.d.ts +2 -0
- package/dist/shared/index2.d.ts.map +1 -1
- package/dist/shared/index3.d.ts +29 -3
- package/dist/shared/index3.d.ts.map +1 -1
- package/dist/shared/index4.d.ts +52 -172
- package/dist/shared/index4.d.ts.map +1 -1
- package/dist/shared/index5.d.ts +208 -58
- package/dist/shared/index5.d.ts.map +1 -1
- package/dist/shared/index6.d.ts +70 -0
- package/dist/shared/index6.d.ts.map +1 -0
- package/dist/shared/marks.js +6 -1
- package/dist/shared/marks.js.map +1 -1
- package/dist/shared/mask.js +107 -0
- package/dist/shared/mask.js.map +1 -0
- package/dist/shared/playwright.js +19 -4
- package/dist/shared/playwright.js.map +1 -1
- package/dist/shared/recordings.js +219 -28
- package/dist/shared/recordings.js.map +1 -1
- package/dist/shared/tasks.js +145 -34
- package/dist/shared/tasks.js.map +1 -1
- package/dist/tailwind/client.d.ts +1 -1
- package/dist/tailwind/index.d.ts +1 -1
- package/dist/tasks/client.d.ts +1 -1
- package/dist/tasks/client.d.ts.map +1 -1
- package/dist/tasks/client.js +271 -56
- package/dist/tasks/client.js.map +1 -1
- package/dist/tasks/index.d.ts +2 -2
- package/dist/voice/client.d.ts.map +1 -1
- package/dist/voice/client.js +35 -14
- package/dist/voice/client.js.map +1 -1
- package/dist/voice/index.d.ts +6 -1
- package/dist/voice/index.d.ts.map +1 -1
- package/dist/voice/index.js +12 -2
- package/dist/voice/index.js.map +1 -1
- package/package.json +41 -2
- package/skills/deictic/SKILL.md +20 -14
- package/skills/deictic/references/install.md +18 -11
- package/skills/deictic/references/recordings.md +29 -0
- package/skills/deictic/references/tasks.md +49 -21
- package/skills/deictic/references/watch.md +38 -11
- package/skills/deictic/scripts/lib.mjs +69 -3
- package/skills/deictic/scripts/recording.mjs +84 -4
- package/skills/deictic/scripts/task.mjs +36 -7
- package/skills/deictic/scripts/vb.mjs +12 -0
- package/skills/deictic/scripts/watch.mjs +74 -10
- package/src/client/away.ts +105 -0
- package/src/client/index.ts +40 -9
- package/src/client/style.ts +1 -0
- package/src/index.ts +14 -2
- package/src/plugins/logs/client.ts +18 -0
- package/src/plugins/logs/index.ts +55 -0
- package/src/plugins/network/client.ts +30 -0
- package/src/plugins/network/index.ts +69 -0
- package/src/plugins/network/mask.ts +133 -0
- package/src/plugins/recommended/index.ts +14 -1
- package/src/plugins/recordings/client.ts +219 -40
- package/src/plugins/recordings/index.ts +108 -23
- package/src/plugins/recordings/marks.ts +6 -0
- package/src/plugins/recordings/replay.ts +127 -4
- package/src/plugins/screenshots/client.ts +35 -0
- package/src/plugins/screenshots/dom.ts +1 -32
- package/src/plugins/screenshots/index.ts +2 -0
- package/src/plugins/screenshots/playwright.ts +15 -4
- package/src/plugins/screenshots/rrweb.ts +2 -1
- package/src/plugins/tasks/client.ts +273 -41
- package/src/plugins/tasks/index.ts +155 -39
- package/src/plugins/tasks/watchers.ts +36 -0
- package/src/plugins/voice/client.ts +33 -11
- package/src/plugins/voice/index.ts +21 -4
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a request is kept as: with what it carries that's a secret blanked, wherever a name says so. The
|
|
3
|
+
* names are all there is to go by, so a secret under a name that says nothing (a token in a path, a password in
|
|
4
|
+
* prose) isn't found: bodies and headers are kept only where asked for, and `ignore` leaves a request out whole.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** A request as rrweb's network plugin has it: all this reads of one, and changes. */
|
|
8
|
+
export interface Request {
|
|
9
|
+
name: string;
|
|
10
|
+
requestHeaders?: Record<string, string>;
|
|
11
|
+
responseHeaders?: Record<string, string>;
|
|
12
|
+
requestBody?: string | null;
|
|
13
|
+
responseBody?: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Masking {
|
|
17
|
+
/** More names whose values are blanked, as these are: a part of the name, in any case. */
|
|
18
|
+
mask: string[];
|
|
19
|
+
/** Requests left out: a part of the URL. */
|
|
20
|
+
ignore: string[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** What a blanked value reads as. */
|
|
24
|
+
export const MASKED = '***';
|
|
25
|
+
/** What's kept of a body at most, in characters. */
|
|
26
|
+
const BODY = 10_000;
|
|
27
|
+
|
|
28
|
+
/** A name with one of these in it holds a secret, in any case: `access_token`, `X-Api-Key`, `Set-Cookie`. */
|
|
29
|
+
const PARTS = [
|
|
30
|
+
'token',
|
|
31
|
+
'secret',
|
|
32
|
+
'passw',
|
|
33
|
+
'pwd',
|
|
34
|
+
'auth',
|
|
35
|
+
'cookie',
|
|
36
|
+
'session',
|
|
37
|
+
'credential',
|
|
38
|
+
'signature',
|
|
39
|
+
'apikey',
|
|
40
|
+
'api-key',
|
|
41
|
+
'api_key',
|
|
42
|
+
'jwt',
|
|
43
|
+
'otp',
|
|
44
|
+
'cvv',
|
|
45
|
+
'cvc',
|
|
46
|
+
'ssn',
|
|
47
|
+
'cardnumber',
|
|
48
|
+
'card_number',
|
|
49
|
+
];
|
|
50
|
+
/** And these whole names, too short to look for inside others: `code` is OAuth's, on its way back. */
|
|
51
|
+
const NAMES = new Set(['key', 'pass', 'code', 'pin', 'sig', 'sid']);
|
|
52
|
+
/** deictic's own requests: a recording sends itself as it goes, which would be a request to record each second. */
|
|
53
|
+
const OURS = '/__deictic/';
|
|
54
|
+
|
|
55
|
+
export const sensitive = (name: string, more: readonly string[] = []): boolean => {
|
|
56
|
+
const lower = name.toLowerCase();
|
|
57
|
+
return NAMES.has(lower) || PARTS.some((part) => lower.includes(part)) || more.some((part) => lower.includes(part.toLowerCase()));
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function maskParams(params: URLSearchParams, more: readonly string[]): boolean {
|
|
61
|
+
let changed = false;
|
|
62
|
+
for (const name of new Set(params.keys())) {
|
|
63
|
+
if (!sensitive(name, more)) continue;
|
|
64
|
+
params.set(name, MASKED);
|
|
65
|
+
changed = true;
|
|
66
|
+
}
|
|
67
|
+
return changed;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** The URL without a name and password before its host, and with its secrets blanked: the query's, and a fragment's that reads as one. */
|
|
71
|
+
export function maskUrl(url: string, more: readonly string[] = []): string {
|
|
72
|
+
let parsed: URL;
|
|
73
|
+
try {
|
|
74
|
+
parsed = new URL(url);
|
|
75
|
+
} catch {
|
|
76
|
+
// Not one this can read: kept as it is, as there's no telling its parts.
|
|
77
|
+
return url;
|
|
78
|
+
}
|
|
79
|
+
let changed = parsed.username !== '' || parsed.password !== '';
|
|
80
|
+
parsed.username = parsed.password = '';
|
|
81
|
+
if (maskParams(parsed.searchParams, more)) changed = true;
|
|
82
|
+
if (parsed.hash.includes('=')) {
|
|
83
|
+
const fragment = new URLSearchParams(parsed.hash.slice(1));
|
|
84
|
+
if (maskParams(fragment, more)) {
|
|
85
|
+
parsed.hash = fragment.toString();
|
|
86
|
+
changed = true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// As it was written where nothing changed: a parsed URL spells some things its own way.
|
|
90
|
+
return changed ? parsed.href.replaceAll(encodeURIComponent(MASKED), MASKED) : url;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function maskHeaders(headers: Record<string, string>, more: readonly string[] = []): Record<string, string> {
|
|
94
|
+
return Object.fromEntries(Object.entries(headers).map(([name, value]) => [name, sensitive(name, more) ? MASKED : value]));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function maskJson(value: unknown, more: readonly string[]): unknown {
|
|
98
|
+
if (Array.isArray(value)) return value.map((item) => maskJson(item, more));
|
|
99
|
+
if (typeof value !== 'object' || value === null) return value;
|
|
100
|
+
return Object.fromEntries(Object.entries(value).map(([name, inner]) => [name, sensitive(name, more) ? MASKED : maskJson(inner, more)]));
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** A body with its secrets blanked where it's JSON or a form's fields, cut where it's long: other text has no names to go by. */
|
|
104
|
+
export function maskBody(body: string, more: readonly string[] = []): string {
|
|
105
|
+
const cut = (text: string) => (text.length > BODY ? `${text.slice(0, BODY)}… (${text.length} characters)` : text);
|
|
106
|
+
const text = body.trim();
|
|
107
|
+
if (text.startsWith('{') || text.startsWith('[')) {
|
|
108
|
+
try {
|
|
109
|
+
return cut(JSON.stringify(maskJson(JSON.parse(text), more)));
|
|
110
|
+
} catch {
|
|
111
|
+
// Not JSON after all.
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// A form's fields: `name=value&…`, with nothing a sentence would have.
|
|
115
|
+
if (/^[^\s=&]+=[^\s&]*(&[^\s=&]+=[^\s&]*)*$/.test(text)) {
|
|
116
|
+
const fields = new URLSearchParams(text);
|
|
117
|
+
if (maskParams(fields, more)) return cut(fields.toString().replaceAll(encodeURIComponent(MASKED), MASKED));
|
|
118
|
+
}
|
|
119
|
+
return cut(body);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** The request as it's kept, or nothing for one left out. */
|
|
123
|
+
export function maskRequest<R extends Request>(request: R, { mask, ignore }: Masking): R | undefined {
|
|
124
|
+
if (request.name.includes(OURS) || ignore.some((part) => request.name.includes(part))) return undefined;
|
|
125
|
+
return {
|
|
126
|
+
...request,
|
|
127
|
+
name: maskUrl(request.name, mask),
|
|
128
|
+
...(request.requestHeaders ? { requestHeaders: maskHeaders(request.requestHeaders, mask) } : {}),
|
|
129
|
+
...(request.responseHeaders ? { responseHeaders: maskHeaders(request.responseHeaders, mask) } : {}),
|
|
130
|
+
...(typeof request.requestBody === 'string' ? { requestBody: maskBody(request.requestBody, mask) } : {}),
|
|
131
|
+
...(typeof request.responseBody === 'string' ? { responseBody: maskBody(request.responseBody, mask) } : {}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* `deictic/recommended`: the plugins for describing a change rather than making it. Alt-click an element, say what
|
|
3
3
|
* should change, attach a screenshot to draw on, a screen recording or your voice, and it goes to a Vercel Board.
|
|
4
|
+
* A recording has the page's console and its requests in it too.
|
|
4
5
|
*
|
|
5
6
|
* Only the server halves, as every factory is: each names its page half, which the integration imports. A plugin
|
|
6
7
|
* outside the preset (Tailwind, your own) goes beside it: `plugins: [...recommended(), tailwind()]`.
|
|
7
8
|
*/
|
|
8
9
|
import type { ServerPlugin } from '#src/index.ts';
|
|
9
10
|
import { annotations, type AnnotationsOptions } from '#src/plugins/annotations/index.ts';
|
|
11
|
+
import { logs, type LogsOptions } from '#src/plugins/logs/index.ts';
|
|
12
|
+
import { network, type NetworkOptions } from '#src/plugins/network/index.ts';
|
|
10
13
|
import { recordings, type RecordingsOptions } from '#src/plugins/recordings/index.ts';
|
|
11
14
|
import { screenshots, type ScreenshotsOptions } from '#src/plugins/screenshots/index.ts';
|
|
12
15
|
import { tasks, type TasksOptions } from '#src/plugins/tasks/index.ts';
|
|
@@ -19,9 +22,16 @@ export interface RecommendedOptions {
|
|
|
19
22
|
annotations?: AnnotationsOptions | false;
|
|
20
23
|
recordings?: RecordingsOptions | false;
|
|
21
24
|
voice?: VoiceOptions | false;
|
|
25
|
+
/** The console's lines in a recording. */
|
|
26
|
+
logs?: LogsOptions | false;
|
|
27
|
+
/** The page's requests in a recording, masked. */
|
|
28
|
+
network?: NetworkOptions | false;
|
|
22
29
|
}
|
|
23
30
|
|
|
24
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Tasks, screenshots, annotations, recordings and voice, in that order, the order of their tabs, then what a
|
|
33
|
+
* recording has besides the page: logs and network.
|
|
34
|
+
*/
|
|
25
35
|
export function recommended(options: RecommendedOptions = {}): ServerPlugin[] {
|
|
26
36
|
const plugins: ServerPlugin[] = [];
|
|
27
37
|
if (options.tasks !== false) plugins.push(tasks(options.tasks));
|
|
@@ -29,6 +39,9 @@ export function recommended(options: RecommendedOptions = {}): ServerPlugin[] {
|
|
|
29
39
|
if (options.annotations !== false) plugins.push(annotations(options.annotations));
|
|
30
40
|
if (options.recordings !== false) plugins.push(recordings(options.recordings));
|
|
31
41
|
if (options.voice !== false) plugins.push(voice(options.voice));
|
|
42
|
+
// Nothing without recordings to be in.
|
|
43
|
+
if (options.recordings !== false && options.logs !== false) plugins.push(logs(options.logs));
|
|
44
|
+
if (options.recordings !== false && options.network !== false) plugins.push(network(options.network));
|
|
32
45
|
return plugins;
|
|
33
46
|
}
|
|
34
47
|
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* The recordings plugin's page half: `record()` starts rrweb (imported then) and shows the toolbar, a bar
|
|
3
3
|
* docked to an edge of the window that its grip drags to any other, kept between recordings. It holds the
|
|
4
|
-
* time, annotate mode's tools where that plugin is loaded, and Stop and Discard.
|
|
5
|
-
*
|
|
4
|
+
* time, annotate mode's tools where that plugin is loaded, and Stop and Discard.
|
|
5
|
+
*
|
|
6
|
+
* The events go to the server as they happen (`begin`, a `part` each second, `end` on Stop), and what the next
|
|
7
|
+
* page needs to carry on is kept in the tab's session storage: a reload, or a link to another page of the site,
|
|
8
|
+
* leaves the recording going. The page that loads starts rrweb again under the same ID, which makes it a
|
|
9
|
+
* recording of several pages as rrweb has them (a `Meta` and a snapshot for each), puts the toolbar back with
|
|
10
|
+
* its time running, and turns the mic back on where it was.
|
|
6
11
|
*
|
|
7
12
|
* Nothing of deictic's is recorded: the overlay is blocked, as rrweb blocks. The marks are, as custom
|
|
8
13
|
* events: the page's annotations and the toolbar's own, which go when it does, as SVGs in page
|
|
@@ -10,12 +15,13 @@
|
|
|
10
15
|
*/
|
|
11
16
|
import { liveWaveform } from '#src/client/waveform.ts';
|
|
12
17
|
import { defineClientPlugin } from '#src/index.ts';
|
|
18
|
+
import type { Shape } from '#src/plugins/annotations/index.ts';
|
|
13
19
|
import type { ResolvedMasking } from '#src/plugins/screenshots/index.ts';
|
|
14
20
|
|
|
15
21
|
import type { Take } from '#src/plugins/voice/index.ts';
|
|
16
22
|
|
|
17
|
-
import type { Kept, Recorder, Recording, VoiceClip } from './index.ts';
|
|
18
|
-
import { END, MARKS } from './marks.ts';
|
|
23
|
+
import type { Kept, Meta, Recorder, Recording, RecordPlugin, VoiceClip } from './index.ts';
|
|
24
|
+
import { END, MARKS, PAGE } from './marks.ts';
|
|
19
25
|
import { dropOurs } from './ours.ts';
|
|
20
26
|
|
|
21
27
|
type Edge = 'top' | 'bottom' | 'left' | 'right';
|
|
@@ -26,6 +32,42 @@ interface Dock {
|
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
const DOCK = 'deictic:recorder';
|
|
35
|
+
/** Where the recording going on is kept, for the tab's next page to carry on with. */
|
|
36
|
+
const GOING = 'deictic:recording';
|
|
37
|
+
/** How often the events are sent, in milliseconds. */
|
|
38
|
+
const EVERY = 1000;
|
|
39
|
+
|
|
40
|
+
/** A recording going on, as the next page needs it. */
|
|
41
|
+
interface Carried {
|
|
42
|
+
id: string;
|
|
43
|
+
startedAt: number;
|
|
44
|
+
/** The next part's place among the parts. */
|
|
45
|
+
seq: number;
|
|
46
|
+
/** The mic's clips so far, and whether it was on. */
|
|
47
|
+
clips: VoiceClip[];
|
|
48
|
+
mic: boolean;
|
|
49
|
+
/** What was drawn from the toolbar, and on which page: it's about that page, so only a reload of it shows it again. */
|
|
50
|
+
path: string;
|
|
51
|
+
marks: Shape[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function carried(): Carried | undefined {
|
|
55
|
+
try {
|
|
56
|
+
return (JSON.parse(sessionStorage.getItem(GOING) ?? 'null') as Carried | null) ?? undefined;
|
|
57
|
+
} catch {
|
|
58
|
+
// Storage can be off: nothing carries over, then.
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function carry(going: Carried | undefined): void {
|
|
64
|
+
try {
|
|
65
|
+
if (going === undefined) sessionStorage.removeItem(GOING);
|
|
66
|
+
else sessionStorage.setItem(GOING, JSON.stringify(going));
|
|
67
|
+
} catch {
|
|
68
|
+
// Not kept, then: a page load ends the recording.
|
|
69
|
+
}
|
|
70
|
+
}
|
|
29
71
|
const MARGIN = 12;
|
|
30
72
|
|
|
31
73
|
const STYLE = `
|
|
@@ -130,27 +172,75 @@ function draggable(bar: HTMLElement, grip: HTMLElement, docked: (dock: Dock) =>
|
|
|
130
172
|
export default defineClientPlugin<never, never, Recorder>({
|
|
131
173
|
name: 'recordings',
|
|
132
174
|
setup: ({ base, root, options, use, request }) => {
|
|
133
|
-
const { masking } = options as { masking: ResolvedMasking };
|
|
134
|
-
let going
|
|
175
|
+
const { masking, canvas } = options as { masking: ResolvedMasking; canvas?: false | { fps: number } };
|
|
176
|
+
let going: Promise<Recording | undefined> | undefined;
|
|
135
177
|
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
178
|
+
const post = async (route: string, body: unknown, keepalive = false) => {
|
|
179
|
+
const res = await request(route, {
|
|
180
|
+
method: 'POST',
|
|
181
|
+
headers: { 'content-type': 'application/json' },
|
|
182
|
+
body: JSON.stringify(body),
|
|
183
|
+
...(keepalive ? { keepalive } : {}),
|
|
139
184
|
});
|
|
140
|
-
|
|
141
|
-
const
|
|
142
|
-
|
|
143
|
-
|
|
185
|
+
// `url`: where it replays, said by what keeps it with no server to serve it from (a `standalone` build).
|
|
186
|
+
const answer = (await res.json()) as { id?: string; url?: string; problem?: string };
|
|
187
|
+
if (answer.id === undefined) throw new Error(`recordings: ${answer.problem ?? res.statusText}`);
|
|
188
|
+
return { id: answer.id, url: answer.url };
|
|
189
|
+
};
|
|
190
|
+
|
|
191
|
+
/** Records until Stop or Discard: a new recording, or `from`, one a page before this started. */
|
|
192
|
+
const record = async (from?: Carried): Promise<Recording | undefined> => {
|
|
193
|
+
const startedAt = from?.startedAt ?? Date.now();
|
|
194
|
+
const begin = async (): Promise<string> => {
|
|
195
|
+
const viewport = { width: document.documentElement.clientWidth, height: document.documentElement.clientHeight };
|
|
196
|
+
const colorScheme = matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
|
197
|
+
return (await post('begin', { page: location.href, viewport, colorScheme, startedAt } satisfies Meta)).id;
|
|
198
|
+
};
|
|
199
|
+
// What else goes in the recording, where its plugin is loaded: the console's lines and the page's requests, each
|
|
200
|
+
// rrweb's own plugin, which listens from when rrweb starts until it stops. One that can't be had (its package
|
|
201
|
+
// isn't installed) is said, and the recording goes on without.
|
|
202
|
+
const extra = (name: 'logs' | 'network'): Promise<RecordPlugin | undefined> | undefined =>
|
|
203
|
+
use(name)
|
|
204
|
+
// A page that carries a recording on made requests before this: those of its load are the recording's too.
|
|
205
|
+
?.plugin({ sinceLoad: from !== undefined })
|
|
206
|
+
.catch((e: unknown) => {
|
|
207
|
+
console.warn(`deictic: this recording has no ${name}`, e);
|
|
208
|
+
return undefined;
|
|
209
|
+
});
|
|
210
|
+
const [rrweb, id, ...extras] = await Promise.all([
|
|
211
|
+
import('rrweb').catch((e: unknown) => {
|
|
212
|
+
throw new Error('recordings need rrweb: add it to your devDependencies', { cause: e });
|
|
213
|
+
}),
|
|
214
|
+
from?.id ?? begin(),
|
|
215
|
+
extra('logs'),
|
|
216
|
+
extra('network'),
|
|
217
|
+
]);
|
|
218
|
+
const clips: VoiceClip[] = from?.clips ?? [];
|
|
219
|
+
// What the server doesn't have yet, and the place of the next part sent.
|
|
220
|
+
let unsent: { type: number; data?: unknown }[] = [];
|
|
221
|
+
let seq = from?.seq ?? 0;
|
|
144
222
|
const host = root.host;
|
|
145
|
-
const keep = dropOurs<(typeof
|
|
223
|
+
const keep = dropOurs<(typeof unsent)[number]>(
|
|
146
224
|
() => rrweb.record.mirror.getId(host),
|
|
147
225
|
() => rrweb.record.mirror.getId(document.documentElement),
|
|
148
226
|
);
|
|
227
|
+
// The page's address changing with no load (a router's `pushState`, Back within the app, a hash), which rrweb
|
|
228
|
+
// doesn't record: a custom event, so the recording says where each stretch happened. Nothing tells of
|
|
229
|
+
// `pushState`, so it's read as each event comes, and as the clock ticks for a route that draws nothing.
|
|
230
|
+
let href = location.href;
|
|
231
|
+
const moved = () => {
|
|
232
|
+
if (location.href === href) return;
|
|
233
|
+
href = location.href;
|
|
234
|
+
rrweb.record.addCustomEvent(PAGE, { href });
|
|
235
|
+
};
|
|
149
236
|
const stopRecording = rrweb.record({
|
|
150
237
|
emit: (event) => {
|
|
238
|
+
// Before what the new route drew, which is what comes next.
|
|
239
|
+
moved();
|
|
151
240
|
const kept = keep(event);
|
|
152
|
-
if (kept !== undefined)
|
|
241
|
+
if (kept !== undefined) unsent.push(kept);
|
|
153
242
|
},
|
|
243
|
+
plugins: extras.filter((plugin) => plugin !== undefined),
|
|
154
244
|
blockClass: masking.blockClass,
|
|
155
245
|
// deictic's own UI, the overlay: a blocked element is kept as an empty box its size, and it has none.
|
|
156
246
|
blockSelector: ['deictic-overlay', ...(masking.blockSelector ? [masking.blockSelector] : [])].join(', '),
|
|
@@ -159,12 +249,18 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
159
249
|
maskAllInputs: masking.maskAllInputs,
|
|
160
250
|
maskInputOptions: { password: true },
|
|
161
251
|
inlineStylesheet: true,
|
|
252
|
+
// A canvas as pictures of it, a few a second and only when it changed: rrweb's other way keeps every call
|
|
253
|
+
// drawn on it, for which it wraps each drawing method of every canvas.
|
|
254
|
+
...(canvas === false || canvas === undefined
|
|
255
|
+
? {}
|
|
256
|
+
: { recordCanvas: true, sampling: { canvas: canvas.fps }, dataURLOptions: { type: 'image/webp', quality: 0.6 } }),
|
|
162
257
|
});
|
|
163
258
|
|
|
164
259
|
// The marks, now and at each change: an SVG whose view is the page from its top left, at 1:1.
|
|
165
260
|
const marks = use('annotations');
|
|
166
261
|
// The toolbar's own, drawn while recording: shown with the page's, gone when it ends.
|
|
167
262
|
const tools = marks?.tools();
|
|
263
|
+
if (from?.path === location.pathname) for (const shape of from.marks) tools?.marks.add(shape);
|
|
168
264
|
const mark = () => {
|
|
169
265
|
const area = { x: -scrollX, y: -scrollY, width: 1, height: 1 };
|
|
170
266
|
rrweb.record.addCustomEvent(MARKS, {
|
|
@@ -174,7 +270,56 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
174
270
|
});
|
|
175
271
|
};
|
|
176
272
|
mark();
|
|
177
|
-
|
|
273
|
+
|
|
274
|
+
// The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.
|
|
275
|
+
const voice = use('voice');
|
|
276
|
+
let take: Take | undefined;
|
|
277
|
+
/** What the next page carries on from, kept as it changes: a page that's going has no time to say it then. */
|
|
278
|
+
let over = false;
|
|
279
|
+
const save = () =>
|
|
280
|
+
// Not once it's ended, as its last events go: the next page would carry on with one that's over.
|
|
281
|
+
over ||
|
|
282
|
+
carry({
|
|
283
|
+
id,
|
|
284
|
+
startedAt,
|
|
285
|
+
seq,
|
|
286
|
+
clips,
|
|
287
|
+
mic: take !== undefined,
|
|
288
|
+
path: location.pathname,
|
|
289
|
+
marks: tools?.marks.list().map((a) => a.shape) ?? [],
|
|
290
|
+
});
|
|
291
|
+
const unsubscribe = [
|
|
292
|
+
marks?.subscribe(mark),
|
|
293
|
+
tools?.marks.subscribe(() => {
|
|
294
|
+
mark();
|
|
295
|
+
save();
|
|
296
|
+
}),
|
|
297
|
+
];
|
|
298
|
+
|
|
299
|
+
// One part at a time, each with its place. A part that didn't arrive goes again with the next, before it.
|
|
300
|
+
let sending: Promise<void> = Promise.resolve();
|
|
301
|
+
const flush = () => {
|
|
302
|
+
const next = sending
|
|
303
|
+
.catch(() => {})
|
|
304
|
+
.then(async () => {
|
|
305
|
+
if (unsent.length === 0) return;
|
|
306
|
+
const part = unsent;
|
|
307
|
+
unsent = [];
|
|
308
|
+
const at = seq++;
|
|
309
|
+
save();
|
|
310
|
+
try {
|
|
311
|
+
await post(`part/${id}?seq=${at}`, part);
|
|
312
|
+
} catch (e) {
|
|
313
|
+
unsent = [...part, ...unsent];
|
|
314
|
+
throw e;
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
sending = next;
|
|
318
|
+
return next;
|
|
319
|
+
};
|
|
320
|
+
// A problem is heard at Stop, where it matters: a part that fails meanwhile goes again a second on.
|
|
321
|
+
const flushing = setInterval(() => void flush().catch(() => {}), EVERY);
|
|
322
|
+
save();
|
|
178
323
|
|
|
179
324
|
return new Promise((done, fail) => {
|
|
180
325
|
const bar = document.createElement('div');
|
|
@@ -188,10 +333,6 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
188
333
|
live.append(dot, time);
|
|
189
334
|
const sep = () => Object.assign(document.createElement('span'), { className: 'sep' });
|
|
190
335
|
|
|
191
|
-
// The mic, where the voice plugin is loaded: each stretch it's on is a clip, at its time in the recording.
|
|
192
|
-
const voice = use('voice');
|
|
193
|
-
const clips: VoiceClip[] = [];
|
|
194
|
-
let take: Take | undefined;
|
|
195
336
|
// The mic's live waveform beside it while it's on, so it's plain it hears.
|
|
196
337
|
const wave = Object.assign(document.createElement('canvas'), { className: 'wave', hidden: true });
|
|
197
338
|
let stopWave: (() => void) | undefined;
|
|
@@ -237,38 +378,55 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
237
378
|
mic.setAttribute('aria-pressed', String(on));
|
|
238
379
|
mic.title = on ? 'Turn the mic off' : 'Turn the mic on';
|
|
239
380
|
mic.setAttribute('aria-label', mic.title);
|
|
381
|
+
save();
|
|
240
382
|
});
|
|
241
383
|
};
|
|
242
384
|
mic?.classList.add('mic');
|
|
243
385
|
mic?.setAttribute('aria-pressed', 'false');
|
|
386
|
+
// On, as the page before left it: a browser that was let use the mic gives it again without asking.
|
|
387
|
+
if (from?.mic === true) toggle();
|
|
388
|
+
|
|
389
|
+
// The page is going, for another or for good, with no time to wait for anything: what's sent of the mic's
|
|
390
|
+
// take is its clip, the next page is told where things stand, and the last events go as the page does.
|
|
391
|
+
const leave = () => {
|
|
392
|
+
const spoken = take?.soFar();
|
|
393
|
+
if (take !== undefined && spoken !== undefined)
|
|
394
|
+
clips.push({ id: spoken.id, at: take.started - startedAt, duration: spoken.duration });
|
|
395
|
+
const part = unsent;
|
|
396
|
+
unsent = [];
|
|
397
|
+
const at = seq++;
|
|
398
|
+
save();
|
|
399
|
+
// Not behind `sending`, which a page that's going never gets to: the server orders the parts by their place.
|
|
400
|
+
// A browser sends 64 KB at most for a page that's gone, so a last second busier than that is lost.
|
|
401
|
+
if (part.length > 0) void post(`part/${id}?seq=${at}`, part, true).catch(() => {});
|
|
402
|
+
};
|
|
403
|
+
addEventListener('pagehide', leave);
|
|
244
404
|
|
|
245
|
-
const end = async (
|
|
405
|
+
const end = async (kept: boolean) => {
|
|
246
406
|
rrweb.record.addCustomEvent(END, {});
|
|
247
407
|
stopRecording?.();
|
|
248
408
|
for (const stop of unsubscribe) stop?.();
|
|
249
409
|
tools?.close();
|
|
410
|
+
clearInterval(flushing);
|
|
250
411
|
clearInterval(ticking);
|
|
251
412
|
removeEventListener('resize', replace);
|
|
413
|
+
removeEventListener('pagehide', leave);
|
|
252
414
|
bar.remove();
|
|
415
|
+
over = true;
|
|
416
|
+
carry(undefined);
|
|
253
417
|
await busy;
|
|
254
|
-
if (!
|
|
418
|
+
if (!kept) {
|
|
255
419
|
unwave();
|
|
256
420
|
take?.cancel();
|
|
421
|
+
void post(`discard/${id}`, {}).catch(() => {});
|
|
257
422
|
return done(undefined);
|
|
258
423
|
}
|
|
259
424
|
await micOff();
|
|
260
425
|
const duration = Date.now() - startedAt;
|
|
261
426
|
const voiced = clips.length > 0 ? { voice: clips } : {};
|
|
262
|
-
const kept: Kept = { page: location.href, viewport, colorScheme, startedAt, duration, events, ...voiced };
|
|
263
427
|
try {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
headers: { 'content-type': 'application/json' },
|
|
267
|
-
body: JSON.stringify(kept),
|
|
268
|
-
});
|
|
269
|
-
// `url`: where it replays, said by what keeps it with no server to serve it from (a `standalone` build).
|
|
270
|
-
const { id, url, problem } = (await res.json()) as { id?: string; url?: string; problem?: string };
|
|
271
|
-
if (id === undefined) throw new Error(`recordings: ${problem ?? res.statusText}`);
|
|
428
|
+
await flush();
|
|
429
|
+
const { url } = await post(`end/${id}`, { duration, ...voiced } satisfies Pick<Kept, 'duration' | 'voice'>);
|
|
272
430
|
done({ id, url: url ?? `${base}__deictic/plugins/recordings/replay/${id}`, duration, ...voiced });
|
|
273
431
|
} catch (e) {
|
|
274
432
|
fail(e);
|
|
@@ -281,7 +439,10 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
281
439
|
bar.prepend(style);
|
|
282
440
|
root.append(bar);
|
|
283
441
|
|
|
284
|
-
const tick = () =>
|
|
442
|
+
const tick = () => {
|
|
443
|
+
moved();
|
|
444
|
+
time.textContent = clock(Date.now() - startedAt);
|
|
445
|
+
};
|
|
285
446
|
tick();
|
|
286
447
|
const ticking = setInterval(tick, 250);
|
|
287
448
|
let dock = storedDock();
|
|
@@ -300,16 +461,34 @@ export default defineClientPlugin<never, never, Recorder>({
|
|
|
300
461
|
});
|
|
301
462
|
};
|
|
302
463
|
|
|
464
|
+
const run = (from?: Carried) => {
|
|
465
|
+
const mine = record(from).finally(() => {
|
|
466
|
+
if (going === mine) going = undefined;
|
|
467
|
+
});
|
|
468
|
+
going = mine;
|
|
469
|
+
return mine;
|
|
470
|
+
};
|
|
471
|
+
// One the page before this left going: carried on at once, whoever asks for it later (`going`), or no one.
|
|
472
|
+
const left = carried();
|
|
473
|
+
if (left !== undefined) {
|
|
474
|
+
run(left).catch((e: unknown) => {
|
|
475
|
+
// Not for the page after this to try again.
|
|
476
|
+
carry(undefined);
|
|
477
|
+
console.warn('deictic: the recording did not carry on, or was not kept', e);
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
// A page shown again as it was left (Back, out of the browser's cache) knows nothing of what happened since:
|
|
481
|
+
// loaded afresh, it carries on like any other.
|
|
482
|
+
window.addEventListener('pageshow', (e) => {
|
|
483
|
+
if (e.persisted && (going !== undefined || carried() !== undefined)) location.reload();
|
|
484
|
+
});
|
|
485
|
+
|
|
303
486
|
return {
|
|
304
|
-
recording: () => going,
|
|
487
|
+
recording: () => going !== undefined,
|
|
488
|
+
going: () => going,
|
|
305
489
|
record: async () => {
|
|
306
|
-
if (going) throw new Error('recordings: one is going already: stop it first');
|
|
307
|
-
|
|
308
|
-
try {
|
|
309
|
-
return await record();
|
|
310
|
-
} finally {
|
|
311
|
-
going = false;
|
|
312
|
-
}
|
|
490
|
+
if (going !== undefined) throw new Error('recordings: one is going already: stop it first');
|
|
491
|
+
return run();
|
|
313
492
|
},
|
|
314
493
|
};
|
|
315
494
|
},
|