@allwright.dev/core 0.1.5 → 0.1.6
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 +1 -1
- package/dist/bootstrap.js +1 -1
- package/dist/browser.d.ts +1 -2
- package/dist/browser.js +1 -42
- package/dist/page.d.ts +3 -1
- package/dist/page.js +57 -0
- package/dist/types.d.ts +17 -15
- package/package.json +1 -1
- package/proto/core/v1/context.proto +28 -0
- package/proto/core/v1/surface.proto +0 -27
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ import { firefox, hooks } from "@allwright.dev/core";
|
|
|
28
28
|
|
|
29
29
|
const browser = await firefox.launch();
|
|
30
30
|
const page = browser.page();
|
|
31
|
-
const hook = await
|
|
31
|
+
const hook = await page.registerHook(hooks.newPage);
|
|
32
32
|
await page.click("a[target=_blank]");
|
|
33
33
|
const newPage = await hook.wait();
|
|
34
34
|
```
|
package/dist/bootstrap.js
CHANGED
|
@@ -12,7 +12,7 @@ const ALLWRIGHT_HOME_ENV_VAR = "ALLWRIGHT_HOME";
|
|
|
12
12
|
const ALLWRIGHT_REPOSITORY_ENV_VAR = "ALLWRIGHT_REPOSITORY";
|
|
13
13
|
const ALLWRIGHT_VERSION_ENV_VAR = "ALLWRIGHT_VERSION";
|
|
14
14
|
const DEFAULT_RELEASE_REPOSITORY = "allwright-dev/allwright";
|
|
15
|
-
const DEFAULT_RELEASE_VERSION = "0.1.
|
|
15
|
+
const DEFAULT_RELEASE_VERSION = "0.1.6";
|
|
16
16
|
const STARTUP_TIMEOUT_MS = 20_000;
|
|
17
17
|
const PING_TIMEOUT_MS = 1_000;
|
|
18
18
|
const PROTO_ROOT = fileURLToPath(new URL("../proto/", import.meta.url));
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Browser, BrowserInfo, BrowserKind, BrowserLaunchState, BrowserType, CommandOptions,
|
|
1
|
+
import type { Browser, BrowserInfo, BrowserKind, BrowserLaunchState, BrowserType, CommandOptions, LaunchOptions, Page } from "./types.js";
|
|
2
2
|
export declare class BrowserTypeImpl implements BrowserType {
|
|
3
3
|
#private;
|
|
4
4
|
constructor(browserKind?: BrowserKind);
|
|
@@ -16,7 +16,6 @@ export declare class BrowserImpl implements Browser {
|
|
|
16
16
|
initialPage(): Page;
|
|
17
17
|
pages(): Page[];
|
|
18
18
|
newPage(options?: CommandOptions): Promise<Page>;
|
|
19
|
-
registerHook<T>(type: HookType<T>): Promise<Hook<T>>;
|
|
20
19
|
close(): Promise<void>;
|
|
21
20
|
ping(message?: string): Promise<string>;
|
|
22
21
|
browserInfo(): BrowserInfo;
|
package/dist/browser.js
CHANGED
|
@@ -66,48 +66,6 @@ export class BrowserImpl {
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
async registerHook(type) {
|
|
70
|
-
this.#ensureOpen();
|
|
71
|
-
if (type.name !== "newPage") {
|
|
72
|
-
throw formatActionError("register hook", `unsupported hook type: ${type.name}`);
|
|
73
|
-
}
|
|
74
|
-
this.#stream.write({ registerHook: { newPage: {} } });
|
|
75
|
-
while (true) {
|
|
76
|
-
const event = await this.#queue.next();
|
|
77
|
-
if (event.hookRegistered?.hookId) {
|
|
78
|
-
const hookId = event.hookRegistered.hookId;
|
|
79
|
-
return {
|
|
80
|
-
id: hookId,
|
|
81
|
-
type,
|
|
82
|
-
wait: (options = {}) => this.#waitForHook(hookId, type, options),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
if (event.error?.message) {
|
|
86
|
-
throw formatActionError(`register ${type.name} hook`, event.error.message);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
async #waitForHook(hookId, type, options) {
|
|
91
|
-
this.#ensureOpen();
|
|
92
|
-
this.#stream.write({
|
|
93
|
-
waitForHook: {
|
|
94
|
-
hookId,
|
|
95
|
-
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
96
|
-
},
|
|
97
|
-
});
|
|
98
|
-
while (true) {
|
|
99
|
-
const event = await this.#queue.next();
|
|
100
|
-
if (event.hookCompleted?.hookId === hookId) {
|
|
101
|
-
if (type.name === "newPage" && event.hookCompleted.newPage?.contextSessionId) {
|
|
102
|
-
return this.#createPage(event.hookCompleted.newPage.contextSessionId);
|
|
103
|
-
}
|
|
104
|
-
throw formatActionError(`wait for ${type.name} hook`, "hook returned an invalid result");
|
|
105
|
-
}
|
|
106
|
-
if (event.error?.message) {
|
|
107
|
-
throw formatActionError(`wait for ${type.name} hook`, event.error.message);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
69
|
async close() {
|
|
112
70
|
if (this.#closed) {
|
|
113
71
|
return;
|
|
@@ -171,6 +129,7 @@ export class BrowserImpl {
|
|
|
171
129
|
runtime: this.#runtime,
|
|
172
130
|
browserSessionId: this.sessionId,
|
|
173
131
|
sessionId,
|
|
132
|
+
createPage: (newSessionId) => this.#createPage(newSessionId),
|
|
174
133
|
});
|
|
175
134
|
this.#pages.set(sessionId, page);
|
|
176
135
|
return page;
|
package/dist/page.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { WebLocatorBuilders, type LocatorFilterOptions } from "./web-locators.js";
|
|
2
|
-
import type { AccessibilitySnapshotOptions, ClickResult, CommandOptions, CountResult, ElementResult, FillResult, HighlightOptions, HighlightResult, Locator, NavigateResult, Page, PageInfo, PressOptions, PressResult, RuntimeClient, ScreenshotOptions, ScreenshotResult, TextResult, WaitForSelectorOptions, WaitForSelectorResult } from "./types.js";
|
|
2
|
+
import type { AccessibilitySnapshotOptions, ClickResult, CommandOptions, CountResult, ElementResult, FillResult, HighlightOptions, HighlightResult, Hook, HookType, Locator, NavigateResult, Page, PageInfo, PressOptions, PressResult, RuntimeClient, ScreenshotOptions, ScreenshotResult, TextResult, WaitForSelectorOptions, WaitForSelectorResult } from "./types.js";
|
|
3
3
|
export declare class PageImpl extends WebLocatorBuilders implements Page {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(input: PageInfo & {
|
|
6
6
|
runtime: RuntimeClient;
|
|
7
|
+
createPage?: (sessionId: string) => Page;
|
|
7
8
|
});
|
|
8
9
|
readonly sessionId: string;
|
|
9
10
|
readonly browserSessionId: string;
|
|
11
|
+
registerHook<T>(type: HookType<T>): Promise<Hook<T>>;
|
|
10
12
|
locator(selector: string, options?: LocatorFilterOptions): Locator;
|
|
11
13
|
goto(url: string, options?: CommandOptions): Promise<NavigateResult>;
|
|
12
14
|
click(selector: string, options?: CommandOptions): Promise<ClickResult>;
|
package/dist/page.js
CHANGED
|
@@ -7,14 +7,71 @@ import { createPageHandle } from "./runtime.js";
|
|
|
7
7
|
export class PageImpl extends WebLocatorBuilders {
|
|
8
8
|
#runtime;
|
|
9
9
|
#handlePromise = null;
|
|
10
|
+
#createPage;
|
|
10
11
|
constructor(input) {
|
|
11
12
|
super();
|
|
12
13
|
this.#runtime = input.runtime;
|
|
13
14
|
this.sessionId = input.sessionId;
|
|
14
15
|
this.browserSessionId = input.browserSessionId;
|
|
16
|
+
this.#createPage = input.createPage ?? ((sessionId) => new PageImpl({
|
|
17
|
+
runtime: this.#runtime,
|
|
18
|
+
browserSessionId: this.browserSessionId,
|
|
19
|
+
sessionId,
|
|
20
|
+
createPage: this.#createPage,
|
|
21
|
+
}));
|
|
15
22
|
}
|
|
16
23
|
sessionId;
|
|
17
24
|
browserSessionId;
|
|
25
|
+
async registerHook(type) {
|
|
26
|
+
if (type.name !== "newPage") {
|
|
27
|
+
throw formatActionError("register hook", `unsupported hook type: ${type.name}`);
|
|
28
|
+
}
|
|
29
|
+
const handle = await this.#getHandle();
|
|
30
|
+
this.#ensureOpen(handle);
|
|
31
|
+
handle.stream.write({
|
|
32
|
+
surfaceSessionId: this.browserSessionId,
|
|
33
|
+
contextSessionId: this.sessionId,
|
|
34
|
+
registerHook: { newPage: {} },
|
|
35
|
+
});
|
|
36
|
+
while (true) {
|
|
37
|
+
const event = await handle.queue.next();
|
|
38
|
+
if (event.hookRegistered?.hookId) {
|
|
39
|
+
const hookId = event.hookRegistered.hookId;
|
|
40
|
+
return {
|
|
41
|
+
id: hookId,
|
|
42
|
+
type,
|
|
43
|
+
wait: (options = {}) => this.#waitForHook(hookId, type, options),
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
if (event.error?.message) {
|
|
47
|
+
throw formatActionError(`register ${type.name} hook`, event.error.message);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async #waitForHook(hookId, type, options) {
|
|
52
|
+
const handle = await this.#getHandle();
|
|
53
|
+
this.#ensureOpen(handle);
|
|
54
|
+
handle.stream.write({
|
|
55
|
+
surfaceSessionId: this.browserSessionId,
|
|
56
|
+
contextSessionId: this.sessionId,
|
|
57
|
+
waitForHook: {
|
|
58
|
+
hookId,
|
|
59
|
+
retryOptions: options.timeoutMs ? { timeoutMs: options.timeoutMs } : undefined,
|
|
60
|
+
},
|
|
61
|
+
});
|
|
62
|
+
while (true) {
|
|
63
|
+
const event = await handle.queue.next();
|
|
64
|
+
if (event.hookCompleted?.hookId === hookId) {
|
|
65
|
+
if (type.name === "newPage" && event.hookCompleted.newPage?.contextSessionId) {
|
|
66
|
+
return this.#createPage(event.hookCompleted.newPage.contextSessionId);
|
|
67
|
+
}
|
|
68
|
+
throw formatActionError(`wait for ${type.name} hook`, "hook returned an invalid result");
|
|
69
|
+
}
|
|
70
|
+
if (event.error?.message) {
|
|
71
|
+
throw formatActionError(`wait for ${type.name} hook`, event.error.message);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
18
75
|
locator(selector, options) {
|
|
19
76
|
const result = new LocatorImpl({ page: this, selector: normalizeSelectorForTransport(selector) });
|
|
20
77
|
return options ? result.filter(options) : result;
|
package/dist/types.d.ts
CHANGED
|
@@ -115,12 +115,12 @@ export interface Browser extends BrowserInfo {
|
|
|
115
115
|
pages(): Page[];
|
|
116
116
|
newPage(options?: CommandOptions): Promise<Page>;
|
|
117
117
|
newTab(options?: CommandOptions): Promise<Page>;
|
|
118
|
-
registerHook<T>(type: HookType<T>): Promise<Hook<T>>;
|
|
119
118
|
close(): Promise<void>;
|
|
120
119
|
ping(message?: string): Promise<string>;
|
|
121
120
|
browserInfo(): BrowserInfo;
|
|
122
121
|
}
|
|
123
122
|
export interface Page extends PageInfo, WebLocators {
|
|
123
|
+
registerHook<T>(type: HookType<T>): Promise<Hook<T>>;
|
|
124
124
|
accessibilitySnapshot(options?: AccessibilitySnapshotOptions): Promise<string>;
|
|
125
125
|
locator(selector: string, options?: LocatorFilterOptions): Locator;
|
|
126
126
|
goto(url: string, options?: CommandOptions): Promise<NavigateResult>;
|
|
@@ -349,18 +349,6 @@ export interface SurfaceSessionEvent {
|
|
|
349
349
|
contextSessionId?: string;
|
|
350
350
|
note?: string;
|
|
351
351
|
};
|
|
352
|
-
hookRegistered?: {
|
|
353
|
-
hookId?: string;
|
|
354
|
-
hookType?: number;
|
|
355
|
-
};
|
|
356
|
-
hookCompleted?: {
|
|
357
|
-
hookId?: string;
|
|
358
|
-
hookType?: number;
|
|
359
|
-
newPage?: {
|
|
360
|
-
contextSessionId?: string;
|
|
361
|
-
note?: string;
|
|
362
|
-
};
|
|
363
|
-
};
|
|
364
352
|
pong?: {
|
|
365
353
|
message?: string;
|
|
366
354
|
};
|
|
@@ -390,6 +378,16 @@ export interface ContextSessionEvent {
|
|
|
390
378
|
error?: {
|
|
391
379
|
message?: string;
|
|
392
380
|
};
|
|
381
|
+
hookRegistered?: {
|
|
382
|
+
hookId?: string;
|
|
383
|
+
};
|
|
384
|
+
hookCompleted?: {
|
|
385
|
+
hookId?: string;
|
|
386
|
+
newPage?: {
|
|
387
|
+
contextSessionId?: string;
|
|
388
|
+
note?: string;
|
|
389
|
+
};
|
|
390
|
+
};
|
|
393
391
|
navigated?: {
|
|
394
392
|
url?: string;
|
|
395
393
|
note?: string;
|
|
@@ -479,11 +477,15 @@ export interface OpenContextRequest {
|
|
|
479
477
|
};
|
|
480
478
|
}
|
|
481
479
|
export interface RegisterHookRequest {
|
|
480
|
+
surfaceSessionId: string;
|
|
481
|
+
contextSessionId: string;
|
|
482
482
|
registerHook: {
|
|
483
483
|
newPage?: Record<string, never>;
|
|
484
484
|
};
|
|
485
485
|
}
|
|
486
486
|
export interface WaitForHookRequest {
|
|
487
|
+
surfaceSessionId: string;
|
|
488
|
+
contextSessionId: string;
|
|
487
489
|
waitForHook: {
|
|
488
490
|
hookId: string;
|
|
489
491
|
retryOptions?: {
|
|
@@ -669,8 +671,8 @@ export interface CloseContextRequest {
|
|
|
669
671
|
contextSessionId: string;
|
|
670
672
|
close: Record<string, never>;
|
|
671
673
|
}
|
|
672
|
-
export type SurfaceSessionRequest = LaunchBrowserRequest | LaunchChromeRequest | OpenContextRequest |
|
|
673
|
-
export type ContextSessionRequest = ContextPingRequest | NavigateRequest | ClickRequest | CountRequest | HighlightRequest | FocusRequest | FillRequest | HoverRequest | PressRequest | TextContentRequest | InnerTextRequest | WaitForSelectorRequest | AccessibilitySnapshotRequest | ScreenshotRequest | CloseContextRequest;
|
|
674
|
+
export type SurfaceSessionRequest = LaunchBrowserRequest | LaunchChromeRequest | OpenContextRequest | ConnectMobileRequest | LaunchAppRequest | SurfacePingRequest | CloseSurfaceRequest;
|
|
675
|
+
export type ContextSessionRequest = ContextPingRequest | RegisterHookRequest | WaitForHookRequest | NavigateRequest | ClickRequest | CountRequest | HighlightRequest | FocusRequest | FillRequest | HoverRequest | PressRequest | TextContentRequest | InnerTextRequest | WaitForSelectorRequest | AccessibilitySnapshotRequest | ScreenshotRequest | CloseContextRequest;
|
|
674
676
|
export type SurfaceSessionStream = grpc.ClientDuplexStream<SurfaceSessionRequest, SurfaceSessionEvent>;
|
|
675
677
|
export type ContextSessionStream = grpc.ClientDuplexStream<ContextSessionRequest, ContextSessionEvent>;
|
|
676
678
|
export interface EngineServiceClientShape {
|
package/package.json
CHANGED
|
@@ -6,6 +6,7 @@ option java_package = "dev.allwright.engine.v1";
|
|
|
6
6
|
option java_multiple_files = true;
|
|
7
7
|
|
|
8
8
|
import "core/v1/common.proto";
|
|
9
|
+
import "surfaces/web/v1/web.proto";
|
|
9
10
|
|
|
10
11
|
message ContextSessionCommand {
|
|
11
12
|
string surface_session_id = 1;
|
|
@@ -27,6 +28,8 @@ message ContextSessionCommand {
|
|
|
27
28
|
WaitForSelectorCommand wait_for_selector = 15;
|
|
28
29
|
ScreenshotCommand screenshot = 16;
|
|
29
30
|
AccessibilitySnapshotCommand accessibility_snapshot = 17;
|
|
31
|
+
RegisterHookCommand register_hook = 18;
|
|
32
|
+
WaitForHookCommand wait_for_hook = 19;
|
|
30
33
|
}
|
|
31
34
|
}
|
|
32
35
|
|
|
@@ -58,6 +61,8 @@ message ContextSessionEvent {
|
|
|
58
61
|
SelectorWaitSatisfiedEvent selector_wait_satisfied = 17;
|
|
59
62
|
ScreenshotCapturedEvent screenshot_captured = 18;
|
|
60
63
|
AccessibilitySnapshotCapturedEvent accessibility_snapshot_captured = 19;
|
|
64
|
+
HookRegisteredEvent hook_registered = 20;
|
|
65
|
+
HookCompletedEvent hook_completed = 21;
|
|
61
66
|
}
|
|
62
67
|
}
|
|
63
68
|
|
|
@@ -77,6 +82,29 @@ message ContextSessionErrorEvent {
|
|
|
77
82
|
string message = 1;
|
|
78
83
|
}
|
|
79
84
|
|
|
85
|
+
message RegisterHookCommand {
|
|
86
|
+
oneof hook {
|
|
87
|
+
RegisterNewPageHook new_page = 1;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
message WaitForHookCommand {
|
|
92
|
+
string hook_id = 1;
|
|
93
|
+
optional CommandRetryOptions retry_options = 2;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
message HookRegisteredEvent {
|
|
97
|
+
string hook_id = 1;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
message HookCompletedEvent {
|
|
101
|
+
string hook_id = 1;
|
|
102
|
+
|
|
103
|
+
oneof result {
|
|
104
|
+
NewPageHookResult new_page = 2;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
80
108
|
message NavigatePageCommand {
|
|
81
109
|
string url = 1;
|
|
82
110
|
optional CommandRetryOptions retry_options = 2;
|
|
@@ -18,8 +18,6 @@ message SurfaceSessionCommand {
|
|
|
18
18
|
LaunchBrowserCommand launch_browser = 5;
|
|
19
19
|
ConnectMobileCommand connect_mobile = 6;
|
|
20
20
|
LaunchAppCommand launch_app = 7;
|
|
21
|
-
RegisterHookCommand register_hook = 8;
|
|
22
|
-
WaitForHookCommand wait_for_hook = 9;
|
|
23
21
|
}
|
|
24
22
|
}
|
|
25
23
|
|
|
@@ -33,17 +31,6 @@ message SessionPingCommand {
|
|
|
33
31
|
|
|
34
32
|
message CloseSurfaceSessionCommand {}
|
|
35
33
|
|
|
36
|
-
message RegisterHookCommand {
|
|
37
|
-
oneof hook {
|
|
38
|
-
RegisterNewPageHook new_page = 1;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
message WaitForHookCommand {
|
|
43
|
-
string hook_id = 1;
|
|
44
|
-
optional CommandRetryOptions retry_options = 2;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
34
|
message SurfaceSessionEvent {
|
|
48
35
|
string session_id = 1;
|
|
49
36
|
|
|
@@ -56,8 +43,6 @@ message SurfaceSessionEvent {
|
|
|
56
43
|
BrowserLaunchedEvent browser_launched = 7;
|
|
57
44
|
MobileConnectedEvent mobile_connected = 8;
|
|
58
45
|
AppLaunchedEvent app_launched = 9;
|
|
59
|
-
HookRegisteredEvent hook_registered = 10;
|
|
60
|
-
HookCompletedEvent hook_completed = 11;
|
|
61
46
|
}
|
|
62
47
|
}
|
|
63
48
|
|
|
@@ -77,15 +62,3 @@ message SurfaceSessionClosedEvent {
|
|
|
77
62
|
message SurfaceSessionErrorEvent {
|
|
78
63
|
string message = 1;
|
|
79
64
|
}
|
|
80
|
-
|
|
81
|
-
message HookRegisteredEvent {
|
|
82
|
-
string hook_id = 1;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
message HookCompletedEvent {
|
|
86
|
-
string hook_id = 1;
|
|
87
|
-
|
|
88
|
-
oneof result {
|
|
89
|
-
NewPageHookResult new_page = 2;
|
|
90
|
-
}
|
|
91
|
-
}
|