-
Notifications
You must be signed in to change notification settings - Fork 175
Expand file tree
/
Copy pathweb.ts
More file actions
50 lines (48 loc) · 2.26 KB
/
Copy pathweb.ts
File metadata and controls
50 lines (48 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import type { Interactor } from '../interactor-types.ts';
import { AppError } from '../../utils/errors.ts';
import { withDiagnosticTimer } from '../../utils/diagnostics.ts';
import { resolveWebProvider } from '../../platforms/web/provider.ts';
export function createWebInteractor(): Interactor {
const provider = () => resolveWebProvider();
return {
open: (target, options) => provider().open(options?.url ?? target, { url: options?.url }),
openDevice: () => provider().open('about:blank'),
close: (target) => provider().close(target),
tap: (x, y) => provider().click(x, y),
doubleTap: () => unsupportedWebOperation('doubleTap'),
swipe: () => unsupportedWebOperation('swipe'),
pan: () => unsupportedWebOperation('pan'),
fling: () => unsupportedWebOperation('fling'),
longPress: () => unsupportedWebOperation('longPress'),
focus: (x, y) => provider().click(x, y),
type: (text, delayMs) => provider().typeText(text, { delayMs }),
fill: (x, y, text, delayMs) => provider().fill(x, y, text, { delayMs }),
scroll: (direction, options) => provider().scroll(direction, options),
pinch: () => unsupportedWebOperation('pinch'),
screenshot: (outPath, options) => provider().screenshot(outPath, options),
snapshot: async (options) => {
const result = await withDiagnosticTimer(
'snapshot_capture',
async () => await provider().snapshot(options),
{ backend: 'web' },
);
return {
nodes: result.nodes,
truncated: result.truncated ?? false,
backend: 'web',
};
},
back: () => unsupportedWebOperation('back'),
home: () => unsupportedWebOperation('home'),
rotate: () => unsupportedWebOperation('rotate'),
rotateGesture: () => unsupportedWebOperation('rotateGesture'),
transformGesture: () => unsupportedWebOperation('transformGesture'),
appSwitcher: () => unsupportedWebOperation('appSwitcher'),
readClipboard: () => unsupportedWebOperation('readClipboard'),
writeClipboard: () => unsupportedWebOperation('writeClipboard'),
setSetting: () => unsupportedWebOperation('setSetting'),
};
}
async function unsupportedWebOperation(operation: string): Promise<never> {
throw new AppError('UNSUPPORTED_OPERATION', `${operation} is not supported on web`);
}