@ricsam/isolate-playwright 0.1.13 → 0.1.14

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.
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Shared handler code for @ricsam/isolate-playwright
3
+ * Used by both index.ts (with isolated-vm) and client.ts (without isolated-vm)
4
+ */
5
+ import type { Page, Locator as PlaywrightLocator, BrowserContext, Response } from "playwright";
6
+ import { type DefaultPlaywrightHandlerMetadata, type DefaultPlaywrightHandlerOptions, type PlaywrightCallback, type PlaywrightSetupOptions } from "./types.ts";
7
+ type ReadFileCallback = NonNullable<PlaywrightSetupOptions['readFile']>;
8
+ type WriteFileCallback = NonNullable<PlaywrightSetupOptions['writeFile']>;
9
+ export interface FileIOCallbacks {
10
+ readFile?: ReadFileCallback;
11
+ writeFile?: WriteFileCallback;
12
+ }
13
+ export declare function getLocator(page: Page, selectorType: string, selectorValue: string, optionsJson: string | null): PlaywrightLocator;
14
+ export declare function executeLocatorAction(locator: PlaywrightLocator, action: string, actionArg: unknown, timeout: number, fileIO?: FileIOCallbacks): Promise<unknown>;
15
+ export declare function executeExpectAssertion(locator: PlaywrightLocator, matcher: string, expected: unknown, negated: boolean, timeout: number): Promise<void>;
16
+ export declare function executePageExpectAssertion(page: Page, matcher: string, expected: unknown, negated: boolean, timeout: number): Promise<void>;
17
+ /**
18
+ * Registry for tracking multiple pages and contexts.
19
+ */
20
+ export interface PlaywrightRegistry {
21
+ pages: Map<string, Page>;
22
+ contexts: Map<string, BrowserContext>;
23
+ nextPageId: number;
24
+ nextContextId: number;
25
+ pendingResponses: Map<string, Promise<Response>>;
26
+ pendingRequests: Map<string, Promise<import("playwright").Request>>;
27
+ nextListenerId: number;
28
+ }
29
+ /**
30
+ * Create a playwright handler from a Page object.
31
+ * This handler is called by the daemon (via callback) when sandbox needs page operations.
32
+ * Used for remote runtime where the browser runs on the client.
33
+ */
34
+ export declare function createPlaywrightHandler(page: Page, options?: DefaultPlaywrightHandlerOptions): PlaywrightCallback;
35
+ /**
36
+ * Public helper for handler-first runtime options.
37
+ * Adds metadata used by adapters for local event capture and collected data.
38
+ */
39
+ export declare function defaultPlaywrightHandler(page: Page, options?: DefaultPlaywrightHandlerOptions): PlaywrightCallback;
40
+ /**
41
+ * Extract metadata from handlers created by defaultPlaywrightHandler().
42
+ */
43
+ export declare function getDefaultPlaywrightHandlerMetadata(handler: PlaywrightCallback): DefaultPlaywrightHandlerMetadata | undefined;
44
+ export {};
@@ -1,92 +1,10 @@
1
1
  import ivm from "isolated-vm";
2
- import type { Page, BrowserContext, BrowserContextOptions } from "playwright";
3
- import type { PlaywrightOperation, PlaywrightResult, PlaywrightEvent, PlaywrightFileData } from "@ricsam/isolate-protocol";
4
- import { DEFAULT_PLAYWRIGHT_HANDLER_META, type DefaultPlaywrightHandlerMetadata, type DefaultPlaywrightHandlerOptions } from "./types.ts";
2
+ import { DEFAULT_PLAYWRIGHT_HANDLER_META } from "./types.ts";
3
+ export { createPlaywrightHandler, defaultPlaywrightHandler, getDefaultPlaywrightHandlerMetadata, } from "./handler.ts";
5
4
  export type { PlaywrightOperation, PlaywrightResult, PlaywrightEvent, PlaywrightFileData } from "@ricsam/isolate-protocol";
6
5
  export { DEFAULT_PLAYWRIGHT_HANDLER_META };
7
- export type ReadFileCallback = (filePath: string) => Promise<PlaywrightFileData> | PlaywrightFileData;
8
- export type WriteFileCallback = (filePath: string, data: Buffer) => Promise<void> | void;
9
- export interface NetworkRequestInfo {
10
- url: string;
11
- method: string;
12
- headers: Record<string, string>;
13
- postData?: string;
14
- resourceType: string;
15
- timestamp: number;
16
- }
17
- export interface NetworkResponseInfo {
18
- url: string;
19
- status: number;
20
- statusText: string;
21
- headers: Record<string, string>;
22
- timestamp: number;
23
- }
24
- /**
25
- * Browser console log entry - logs from the page context (not sandbox).
26
- */
27
- export interface BrowserConsoleLogEntry {
28
- level: string;
29
- stdout: string;
30
- timestamp: number;
31
- }
32
- /**
33
- * Callback type for handling playwright operations.
34
- * Used for remote execution where the page lives on the client.
35
- */
36
- export type PlaywrightCallback = (op: PlaywrightOperation) => Promise<PlaywrightResult>;
37
- /**
38
- * Options for setting up playwright in an isolate.
39
- */
40
- export interface PlaywrightSetupOptions {
41
- /** Direct page object (for local use) */
42
- page?: Page;
43
- /** Handler callback (for remote use - daemon invokes this) */
44
- handler?: PlaywrightCallback;
45
- /** Default timeout for operations */
46
- timeout?: number;
47
- /** If true, browser console logs are printed to stdout */
48
- console?: boolean;
49
- /** Unified event callback for all playwright events */
50
- onEvent?: (event: PlaywrightEvent) => void;
51
- /**
52
- * Callback invoked when context.newPage() is called from within the isolate.
53
- * Host creates/configures the new page. If not provided, newPage() will throw an error.
54
- * Receives the BrowserContext so you can call context.newPage().
55
- * @param context - The BrowserContext that requested the new page
56
- * @returns The new Page object
57
- */
58
- createPage?: (context: BrowserContext) => Promise<Page> | Page;
59
- /**
60
- * Callback invoked when browser.newContext() is called from within the isolate.
61
- * Host creates/configures the new context. If not provided, newContext() will throw an error.
62
- * @param options - Browser context options passed from the isolate
63
- * @returns The new BrowserContext object
64
- */
65
- createContext?: (options?: BrowserContextOptions) => Promise<BrowserContext> | BrowserContext;
66
- }
67
- export interface PlaywrightHandle {
68
- dispose(): void;
69
- /** Get browser console logs (from the page, not sandbox) */
70
- getBrowserConsoleLogs(): BrowserConsoleLogEntry[];
71
- getNetworkRequests(): NetworkRequestInfo[];
72
- getNetworkResponses(): NetworkResponseInfo[];
73
- clearCollected(): void;
74
- }
75
- /**
76
- * Create a playwright handler from a Page object.
77
- * This handler is called by the daemon (via callback) when sandbox needs page operations.
78
- * Used for remote runtime where the browser runs on the client.
79
- */
80
- export declare function createPlaywrightHandler(page: Page, options?: DefaultPlaywrightHandlerOptions): PlaywrightCallback;
81
- /**
82
- * Public helper for handler-first runtime options.
83
- * Adds metadata used by adapter layers for local event capture.
84
- */
85
- export declare function defaultPlaywrightHandler(page: Page, options?: DefaultPlaywrightHandlerOptions): PlaywrightCallback;
86
- /**
87
- * Extract metadata from handlers created by defaultPlaywrightHandler().
88
- */
89
- export declare function getDefaultPlaywrightHandlerMetadata(handler: PlaywrightCallback): DefaultPlaywrightHandlerMetadata | undefined;
6
+ export type { NetworkRequestInfo, NetworkResponseInfo, BrowserConsoleLogEntry, PlaywrightCallback, PlaywrightSetupOptions, PlaywrightHandle, } from "./types.ts";
7
+ import type { PlaywrightSetupOptions, PlaywrightHandle } from "./types.ts";
90
8
  /**
91
9
  * Set up playwright in an isolate context.
92
10
  *
@@ -23,7 +23,7 @@ export interface NetworkResponseInfo {
23
23
  */
24
24
  export interface BrowserConsoleLogEntry {
25
25
  level: string;
26
- args: string[];
26
+ stdout: string;
27
27
  timestamp: number;
28
28
  }
29
29
  /**
@@ -51,6 +51,8 @@ export interface DefaultPlaywrightHandlerOptions {
51
51
  createPage?: (context: import("playwright").BrowserContext) => Promise<import("playwright").Page> | import("playwright").Page;
52
52
  /** Callback to create new contexts when browser.newContext() is called */
53
53
  createContext?: (options?: import("playwright").BrowserContextOptions) => Promise<import("playwright").BrowserContext> | import("playwright").BrowserContext;
54
+ /** Callback to evaluate a predicate function inside the isolate (used by waitForURL/Request/Response with function predicates) */
55
+ evaluatePredicate?: (predicateId: number, data: unknown) => boolean;
54
56
  }
55
57
  /**
56
58
  * Metadata attached to handlers created by defaultPlaywrightHandler().
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ricsam/isolate-playwright",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "main": "./dist/cjs/index.cjs",
5
5
  "types": "./dist/types/index.d.ts",
6
6
  "exports": {