@ricsam/isolate 0.1.4 → 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 +45 -2
- package/dist/cjs/internal/async-context/index.cjs +401 -0
- package/dist/cjs/internal/async-context/index.cjs.map +10 -0
- package/dist/cjs/internal/client/connection.cjs +175 -123
- package/dist/cjs/internal/client/connection.cjs.map +3 -3
- package/dist/cjs/internal/console/index.cjs +2 -2
- package/dist/cjs/internal/console/index.cjs.map +2 -2
- package/dist/cjs/internal/core/index.cjs +22 -6
- package/dist/cjs/internal/core/index.cjs.map +3 -3
- package/dist/cjs/internal/crypto/index.cjs +2 -2
- package/dist/cjs/internal/crypto/index.cjs.map +2 -2
- package/dist/cjs/internal/daemon/connection.cjs +77 -12
- package/dist/cjs/internal/daemon/connection.cjs.map +3 -3
- package/dist/cjs/internal/encoding/index.cjs.map +1 -1
- package/dist/cjs/internal/fetch/index.cjs +119 -18
- package/dist/cjs/internal/fetch/index.cjs.map +3 -3
- package/dist/cjs/internal/fetch/stream-state.cjs.map +1 -1
- package/dist/cjs/internal/fs/index.cjs +2 -2
- package/dist/cjs/internal/fs/index.cjs.map +2 -2
- package/dist/cjs/internal/module-loader/bundle.cjs +277 -1
- package/dist/cjs/internal/module-loader/bundle.cjs.map +3 -3
- package/dist/cjs/internal/path/index.cjs.map +1 -1
- package/dist/cjs/internal/playwright/index.cjs +2 -2
- package/dist/cjs/internal/playwright/index.cjs.map +2 -2
- package/dist/cjs/internal/runtime/index.cjs +78 -6
- package/dist/cjs/internal/runtime/index.cjs.map +3 -3
- package/dist/cjs/internal/test-environment/index.cjs +2 -2
- package/dist/cjs/internal/test-environment/index.cjs.map +2 -2
- package/dist/cjs/internal/timers/index.cjs +42 -7
- package/dist/cjs/internal/timers/index.cjs.map +3 -3
- package/dist/cjs/internal/typecheck/isolate-types.cjs +36 -1
- package/dist/cjs/internal/typecheck/isolate-types.cjs.map +3 -3
- package/dist/cjs/package.json +1 -1
- package/dist/mjs/internal/async-context/index.mjs +361 -0
- package/dist/mjs/internal/async-context/index.mjs.map +10 -0
- package/dist/mjs/internal/client/connection.mjs +176 -123
- package/dist/mjs/internal/client/connection.mjs.map +3 -3
- package/dist/mjs/internal/console/index.mjs +2 -2
- package/dist/mjs/internal/console/index.mjs.map +2 -2
- package/dist/mjs/internal/core/index.mjs +22 -6
- package/dist/mjs/internal/core/index.mjs.map +3 -3
- package/dist/mjs/internal/crypto/index.mjs +2 -2
- package/dist/mjs/internal/crypto/index.mjs.map +2 -2
- package/dist/mjs/internal/daemon/connection.mjs +77 -12
- package/dist/mjs/internal/daemon/connection.mjs.map +3 -3
- package/dist/mjs/internal/encoding/index.mjs.map +1 -1
- package/dist/mjs/internal/fetch/index.mjs +119 -18
- package/dist/mjs/internal/fetch/index.mjs.map +3 -3
- package/dist/mjs/internal/fetch/stream-state.mjs.map +1 -1
- package/dist/mjs/internal/fs/index.mjs +2 -2
- package/dist/mjs/internal/fs/index.mjs.map +2 -2
- package/dist/mjs/internal/module-loader/bundle.mjs +277 -1
- package/dist/mjs/internal/module-loader/bundle.mjs.map +3 -3
- package/dist/mjs/internal/path/index.mjs.map +1 -1
- package/dist/mjs/internal/playwright/index.mjs +2 -2
- package/dist/mjs/internal/playwright/index.mjs.map +2 -2
- package/dist/mjs/internal/runtime/index.mjs +78 -6
- package/dist/mjs/internal/runtime/index.mjs.map +3 -3
- package/dist/mjs/internal/test-environment/index.mjs +2 -2
- package/dist/mjs/internal/test-environment/index.mjs.map +2 -2
- package/dist/mjs/internal/timers/index.mjs +42 -7
- package/dist/mjs/internal/timers/index.mjs.map +3 -3
- package/dist/mjs/internal/typecheck/isolate-types.mjs +36 -1
- package/dist/mjs/internal/typecheck/isolate-types.mjs.map +3 -3
- package/dist/mjs/package.json +1 -1
- package/dist/types/internal/async-context/index.d.ts +5 -0
- package/dist/types/internal/console/index.d.ts +1 -1
- package/dist/types/internal/core/index.d.ts +2 -2
- package/dist/types/internal/crypto/index.d.ts +1 -1
- package/dist/types/internal/daemon/types.d.ts +1 -0
- package/dist/types/internal/encoding/index.d.ts +1 -1
- package/dist/types/internal/fetch/index.d.ts +1 -1
- package/dist/types/internal/fetch/stream-state.d.ts +1 -1
- package/dist/types/internal/fs/index.d.ts +1 -1
- package/dist/types/internal/path/index.d.ts +1 -1
- package/dist/types/internal/playwright/index.d.ts +1 -1
- package/dist/types/internal/test-environment/index.d.ts +1 -1
- package/dist/types/internal/timers/index.d.ts +1 -1
- package/dist/types/internal/typecheck/isolate-types.d.ts +2 -2
- package/package.json +8 -3
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/internal/playwright/index.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
|
-
"import ivm from \"isolated-vm\";\nimport type {\n PlaywrightOperation,\n} from \"../protocol/index.mjs\";\nimport {\n DEFAULT_PLAYWRIGHT_HANDLER_META,\n} from \"./types.mjs\";\n\n// Re-export handler functions from handler.ts\nexport {\n createPlaywrightHandler,\n defaultPlaywrightHandler,\n getDefaultPlaywrightHandlerMetadata,\n} from \"./handler.mjs\";\n\n// Re-export protocol types\nexport type { PlaywrightOperation, PlaywrightResult, PlaywrightEvent, PlaywrightFileData } from \"../protocol/index.mjs\";\nexport { DEFAULT_PLAYWRIGHT_HANDLER_META };\n\n// Re-export types from types.ts\nexport type {\n NetworkRequestInfo,\n NetworkResponseInfo,\n BrowserConsoleLogEntry,\n PageErrorInfo,\n RequestFailureInfo,\n PlaywrightCallback,\n PlaywrightSetupOptions,\n PlaywrightHandle,\n} from \"./types.mjs\";\n\n// Import handler functions for use within this module\nimport {\n createPlaywrightHandler,\n getDefaultPlaywrightHandlerMetadata,\n} from \"./handler.mjs\";\nimport type {\n PlaywrightCallback,\n PlaywrightSetupOptions,\n PlaywrightHandle,\n NetworkRequestInfo,\n NetworkResponseInfo,\n BrowserConsoleLogEntry,\n PageErrorInfo,\n RequestFailureInfo,\n} from \"./types.mjs\";\n\n// ============================================================================\n// Predicate Support Wrapper for Remote Handlers\n// ============================================================================\n\n/**\n * Wraps a remote handler (no direct page access) to support predicate-based\n * waitFor* operations. Predicate ops are handled locally by issuing sub-operations\n * through the handler and evaluating the predicate in the isolate.\n */\nfunction wrapHandlerWithPredicateSupport(\n handler: PlaywrightCallback,\n evaluatePredicate: (predicateId: number, data: unknown) => boolean,\n defaultTimeout: number,\n): PlaywrightCallback {\n return async (op) => {\n switch (op.type) {\n case \"waitForURLPredicate\": {\n const [predicateId, customTimeout, waitUntil] = op.args as [number, number?, string?];\n const effectiveTimeout = customTimeout ?? defaultTimeout;\n const startTime = Date.now();\n const pollInterval = 100;\n\n while (true) {\n // Get current URL via the handler\n const urlResult = await handler({ type: \"url\", args: [], pageId: op.pageId, contextId: op.contextId });\n if (urlResult.ok) {\n try {\n if (evaluatePredicate(predicateId, urlResult.value as string)) {\n return { ok: true };\n }\n } catch (e) {\n const error = e as Error;\n return { ok: false, error: { name: error.name, message: error.message } };\n }\n }\n if (effectiveTimeout > 0 && Date.now() - startTime >= effectiveTimeout) {\n return { ok: false, error: { name: \"Error\", message: `Timeout ${effectiveTimeout}ms exceeded waiting for URL` } };\n }\n await new Promise(r => setTimeout(r, pollInterval));\n }\n }\n case \"waitForResponsePredicateFinish\": {\n const [initialListenerId, predicateId, customTimeout] = op.args as [string, number, number?];\n const effectiveTimeout = customTimeout ?? defaultTimeout;\n const broadMatcher = { type: 'regex' as const, value: { $regex: '.*', $flags: '' } };\n const startTime = Date.now();\n let currentListenerId = initialListenerId;\n\n while (true) {\n // Wait for response data from current listener\n const finishResult = await handler({\n type: \"waitForResponseFinish\",\n args: [currentListenerId],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!finishResult.ok) return finishResult;\n const responseData = finishResult.value as Record<string, unknown>;\n\n // Evaluate predicate\n try {\n const serialized = {\n method: '',\n headers: Object.entries((responseData.headers || {}) as Record<string, string>),\n url: responseData.url as string,\n status: responseData.status as number,\n statusText: responseData.statusText as string,\n body: (responseData.text as string) || '',\n };\n if (evaluatePredicate(predicateId, serialized)) {\n return finishResult;\n }\n } catch (e) {\n const error = e as Error;\n return { ok: false, error: { name: error.name, message: error.message } };\n }\n\n if (effectiveTimeout > 0 && Date.now() - startTime >= effectiveTimeout) {\n return { ok: false, error: { name: \"Error\", message: `Timeout ${effectiveTimeout}ms exceeded waiting for response` } };\n }\n\n // Not matched — start next listener\n const remainingTimeout = effectiveTimeout > 0 ? Math.max(1, effectiveTimeout - (Date.now() - startTime)) : effectiveTimeout;\n const nextStartResult = await handler({\n type: \"waitForResponseStart\",\n args: [broadMatcher, remainingTimeout],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!nextStartResult.ok) return nextStartResult;\n currentListenerId = (nextStartResult.value as { listenerId: string }).listenerId;\n }\n }\n case \"waitForRequestPredicateFinish\": {\n const [initialListenerId, predicateId, customTimeout] = op.args as [string, number, number?];\n const effectiveTimeout = customTimeout ?? defaultTimeout;\n const broadMatcher = { type: 'regex' as const, value: { $regex: '.*', $flags: '' } };\n const startTime = Date.now();\n let currentListenerId = initialListenerId;\n\n while (true) {\n const finishResult = await handler({\n type: \"waitForRequestFinish\",\n args: [currentListenerId],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!finishResult.ok) return finishResult;\n const requestData = finishResult.value as Record<string, unknown>;\n\n try {\n const serialized = {\n method: requestData.method as string,\n headers: Object.entries((requestData.headers || {}) as Record<string, string>),\n url: requestData.url as string,\n body: (requestData.postData as string) || '',\n };\n if (evaluatePredicate(predicateId, serialized)) {\n return finishResult;\n }\n } catch (e) {\n const error = e as Error;\n return { ok: false, error: { name: error.name, message: error.message } };\n }\n\n if (effectiveTimeout > 0 && Date.now() - startTime >= effectiveTimeout) {\n return { ok: false, error: { name: \"Error\", message: `Timeout ${effectiveTimeout}ms exceeded waiting for request` } };\n }\n\n // Not matched — start next listener\n const remainingTimeout = effectiveTimeout > 0 ? Math.max(1, effectiveTimeout - (Date.now() - startTime)) : effectiveTimeout;\n const nextStartResult = await handler({\n type: \"waitForRequestStart\",\n args: [broadMatcher, remainingTimeout],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!nextStartResult.ok) return nextStartResult;\n currentListenerId = (nextStartResult.value as { listenerId: string }).listenerId;\n }\n }\n default:\n return handler(op);\n }\n };\n}\n\n// ============================================================================\n// Setup Playwright\n// ============================================================================\n\n/**\n * Set up playwright in an isolate context.\n *\n * For local use: provide `page` option (direct page access)\n * For remote use: provide `handler` option (callback pattern)\n */\nexport async function setupPlaywright(\n context: ivm.Context,\n options: PlaywrightSetupOptions\n): Promise<PlaywrightHandle> {\n const timeout = options.timeout ?? 30000;\n\n // Determine if we have a page or handler.\n // Handlers created via defaultPlaywrightHandler() carry page metadata so\n // event capture/collected data keeps working in handler-first mode.\n const explicitPage = \"page\" in options ? options.page : undefined;\n const handler = \"handler\" in options ? options.handler : undefined;\n const handlerMetadata = handler\n ? getDefaultPlaywrightHandlerMetadata(handler)\n : undefined;\n const page = explicitPage ?? handlerMetadata?.page;\n\n // Get lifecycle callbacks\n const createPage = \"createPage\" in options ? options.createPage : undefined;\n const createContext = \"createContext\" in options ? options.createContext : undefined;\n const readFile = \"readFile\" in options ? options.readFile : undefined;\n const writeFile = \"writeFile\" in options ? options.writeFile : undefined;\n\n if (!handler && !page) {\n throw new Error(\"Either page or handler must be provided to setupPlaywright\");\n }\n\n // State for collected data (only used when page is provided directly)\n const browserConsoleLogs: BrowserConsoleLogEntry[] = [];\n const pageErrors: PageErrorInfo[] = [];\n const networkRequests: NetworkRequestInfo[] = [];\n const networkResponses: NetworkResponseInfo[] = [];\n const requestFailures: RequestFailureInfo[] = [];\n\n const global = context.global;\n\n // ========================================================================\n // Event Capture (only when page is provided directly)\n // ========================================================================\n\n let requestHandler: ((request: import(\"playwright\").Request) => void) | undefined;\n let responseHandler: ((response: import(\"playwright\").Response) => void) | undefined;\n let requestFailedHandler: ((request: import(\"playwright\").Request) => void) | undefined;\n let consoleHandler: ((msg: import(\"playwright\").ConsoleMessage) => void) | undefined;\n let pageErrorHandler: ((error: Error) => void) | undefined;\n\n if (page) {\n // Get onEvent callback if provided\n const onEvent = \"onEvent\" in options ? options.onEvent : undefined;\n const requestIds = new WeakMap<import(\"playwright\").Request, string>();\n let nextRequestId = 1;\n const getRequestId = (request: import(\"playwright\").Request): string => {\n let requestId = requestIds.get(request);\n if (!requestId) {\n requestId = `req_${nextRequestId++}`;\n requestIds.set(request, requestId);\n }\n return requestId;\n };\n const toLocation = (\n location: { url?: string; lineNumber?: number; columnNumber?: number } | undefined,\n ): BrowserConsoleLogEntry[\"location\"] => {\n if (!location || (!location.url && location.lineNumber == null && location.columnNumber == null)) {\n return undefined;\n }\n\n return {\n url: location.url || undefined,\n lineNumber: location.lineNumber != null ? location.lineNumber + 1 : undefined,\n columnNumber: location.columnNumber != null ? location.columnNumber + 1 : undefined,\n };\n };\n\n requestHandler = (request: import(\"playwright\").Request) => {\n const info: NetworkRequestInfo = {\n requestId: getRequestId(request),\n url: request.url(),\n method: request.method(),\n headers: request.headers(),\n postData: request.postData() ?? undefined,\n resourceType: request.resourceType(),\n timestamp: Date.now(),\n };\n networkRequests.push(info);\n\n if (onEvent) {\n onEvent({\n type: \"networkRequest\",\n requestId: info.requestId,\n url: info.url,\n method: info.method,\n headers: info.headers,\n postData: info.postData,\n resourceType: info.resourceType,\n timestamp: info.timestamp,\n });\n }\n };\n\n responseHandler = (response: import(\"playwright\").Response) => {\n const request = response.request();\n const info: NetworkResponseInfo = {\n requestId: getRequestId(request),\n url: response.url(),\n status: response.status(),\n statusText: response.statusText(),\n headers: response.headers(),\n resourceType: request.resourceType(),\n timestamp: Date.now(),\n };\n networkResponses.push(info);\n\n if (onEvent) {\n onEvent({\n type: \"networkResponse\",\n requestId: info.requestId,\n url: info.url,\n status: info.status,\n statusText: info.statusText,\n headers: info.headers,\n resourceType: info.resourceType,\n timestamp: info.timestamp,\n });\n }\n };\n\n requestFailedHandler = (request: import(\"playwright\").Request) => {\n const info: RequestFailureInfo = {\n requestId: getRequestId(request),\n url: request.url(),\n method: request.method(),\n failureText: request.failure()?.errorText || \"request failed\",\n resourceType: request.resourceType(),\n timestamp: Date.now(),\n };\n requestFailures.push(info);\n\n if (onEvent) {\n onEvent({\n type: \"requestFailure\",\n requestId: info.requestId,\n url: info.url,\n method: info.method,\n failureText: info.failureText,\n resourceType: info.resourceType,\n timestamp: info.timestamp,\n });\n }\n };\n\n consoleHandler = (msg: import(\"playwright\").ConsoleMessage) => {\n const args = msg.args().map((arg) => String(arg));\n const entry: BrowserConsoleLogEntry = {\n level: msg.type(),\n stdout: args.join(\" \"),\n location: toLocation(msg.location()),\n timestamp: Date.now(),\n };\n browserConsoleLogs.push(entry);\n\n if (onEvent) {\n onEvent({\n type: \"browserConsoleLog\",\n level: entry.level,\n stdout: entry.stdout,\n location: entry.location,\n timestamp: entry.timestamp,\n });\n }\n\n // Print to stdout if console option is true\n if (\"console\" in options && options.console) {\n const prefix = `[browser:${entry.level}]`;\n console.log(prefix, entry.stdout);\n }\n };\n\n pageErrorHandler = (error: Error) => {\n const entry: PageErrorInfo = {\n name: error.name,\n message: error.message,\n stack: error.stack,\n timestamp: Date.now(),\n };\n pageErrors.push(entry);\n\n if (onEvent) {\n onEvent({\n type: \"pageError\",\n name: entry.name,\n message: entry.message,\n stack: entry.stack,\n timestamp: entry.timestamp,\n });\n }\n };\n\n page.on(\"request\", requestHandler);\n page.on(\"response\", responseHandler);\n page.on(\"requestfailed\", requestFailedHandler);\n page.on(\"console\", consoleHandler);\n page.on(\"pageerror\", pageErrorHandler);\n }\n\n // ========================================================================\n // Injected JavaScript\n // ========================================================================\n\n // Helper function to invoke handler and handle errors\n context.evalSync(`\n(function() {\n globalThis.__pw_invoke = async function(type, args, options) {\n const op = JSON.stringify({ type, args, pageId: options?.pageId, contextId: options?.contextId });\n const resultJson = await __Playwright_handler_ref.apply(\n undefined,\n [op],\n { result: { promise: true, copy: true } }\n );\n const result = JSON.parse(resultJson);\n if (result.ok) {\n return result.value;\n }\n const error = new Error(result.error.message);\n error.name = result.error.name;\n throw error;\n };\n})();\n`);\n\n // Predicate registry for waitForURL/Request/Response with function predicates\n context.evalSync(`\n(function() {\n const __pw_predicates = new Map();\n let __pw_next_id = 0;\n globalThis.__pw_register_predicate = function(fn) {\n const id = __pw_next_id++;\n __pw_predicates.set(id, fn);\n return id;\n };\n globalThis.__pw_unregister_predicate = function(id) {\n __pw_predicates.delete(id);\n };\n globalThis.__pw_evaluate_predicate = function(id, data) {\n const fn = __pw_predicates.get(id);\n if (!fn) throw new Error('Predicate not found: ' + id);\n const result = fn(data);\n if (result && typeof result === 'object' && typeof result.then === 'function') {\n throw new Error('Async predicates are not supported. Use a synchronous predicate function.');\n }\n return !!result;\n };\n})();\n`);\n\n // Get reference to the predicate evaluation function for host-side use\n const evaluatePredicateRef = context.global.getSync(\n '__pw_evaluate_predicate', { reference: true }\n ) as ivm.Reference<(id: number, data: unknown) => boolean>;\n\n // ========================================================================\n // Create Handler and Unified Handler Reference\n // ========================================================================\n\n const evaluatePredicateFn = (predicateId: number, data: unknown): boolean => {\n return evaluatePredicateRef.applySync(\n undefined,\n [new ivm.ExternalCopy(predicateId).copyInto(), new ivm.ExternalCopy(data).copyInto()]\n ) as boolean;\n };\n\n // Create handler with evaluatePredicate support.\n // When a page is available (either directly or through handler metadata),\n // create a handler with evaluatePredicate for efficient event-based predicate evaluation.\n // When only a remote handler is available (no page), wrap it to intercept predicate\n // operations and implement them via polling/sub-operations.\n let effectiveHandler: PlaywrightCallback;\n if (handler && handlerMetadata?.page) {\n // Handler-first mode with page metadata — recreate with evaluatePredicate\n effectiveHandler = createPlaywrightHandler(handlerMetadata.page, {\n ...handlerMetadata.options,\n evaluatePredicate: evaluatePredicateFn,\n });\n } else if (handler) {\n // Remote handler without page — wrap to handle predicate ops locally\n effectiveHandler = wrapHandlerWithPredicateSupport(handler, evaluatePredicateFn, timeout);\n } else if (page) {\n effectiveHandler = createPlaywrightHandler(page, {\n timeout,\n readFile,\n writeFile,\n createPage,\n createContext,\n evaluatePredicate: evaluatePredicateFn,\n });\n } else {\n throw new Error(\"Either page or handler must be provided to setupPlaywright\");\n }\n\n // Single handler reference that receives operation objects\n global.setSync(\n \"__Playwright_handler_ref\",\n new ivm.Reference(async (opJson: string): Promise<string> => {\n const op = JSON.parse(opJson) as PlaywrightOperation;\n const result = await effectiveHandler(op);\n return JSON.stringify(result);\n })\n );\n\n // IsolatePage class and page/context/browser globals\n context.evalSync(`\n(function() {\n // IsolatePage class - represents a page with a specific pageId\n class IsolatePage {\n #pageId; #contextId;\n constructor(pageId, contextId) {\n this.#pageId = pageId;\n this.#contextId = contextId;\n }\n get __isPage() { return true; }\n get __pageId() { return this.#pageId; }\n get __contextId() { return this.#contextId; }\n\n async goto(url, options) {\n await __pw_invoke(\"goto\", [url, options?.waitUntil || null], { pageId: this.#pageId });\n }\n async reload() {\n await __pw_invoke(\"reload\", [], { pageId: this.#pageId });\n }\n async url() { return __pw_invoke(\"url\", [], { pageId: this.#pageId }); }\n async title() { return __pw_invoke(\"title\", [], { pageId: this.#pageId }); }\n async content() { return __pw_invoke(\"content\", [], { pageId: this.#pageId }); }\n async waitForSelector(selector, options) {\n return __pw_invoke(\"waitForSelector\", [selector, options ? JSON.stringify(options) : null], { pageId: this.#pageId });\n }\n async waitForTimeout(ms) { return __pw_invoke(\"waitForTimeout\", [ms], { pageId: this.#pageId }); }\n async waitForLoadState(state) { return __pw_invoke(\"waitForLoadState\", [state || null], { pageId: this.#pageId }); }\n async evaluate(script, arg) {\n const hasArg = arguments.length > 1;\n if (hasArg) {\n const serialized = typeof script === \"function\" ? script.toString() : script;\n return __pw_invoke(\"evaluate\", [serialized, arg], { pageId: this.#pageId });\n }\n const serialized = typeof script === \"function\" ? \"(\" + script.toString() + \")()\" : script;\n return __pw_invoke(\"evaluate\", [serialized], { pageId: this.#pageId });\n }\n locator(selector) { return new Locator(\"css\", selector, null, this.#pageId); }\n getByRole(role, options) {\n if (options) {\n const serialized = { ...options };\n const name = options.name;\n if (name && typeof name === 'object' && typeof name.source === 'string' && typeof name.flags === 'string') {\n serialized.name = { $regex: name.source, $flags: name.flags };\n }\n return new Locator(\"role\", role, JSON.stringify(serialized), this.#pageId);\n }\n return new Locator(\"role\", role, null, this.#pageId);\n }\n getByText(text) { return new Locator(\"text\", text, null, this.#pageId); }\n getByLabel(label) { return new Locator(\"label\", label, null, this.#pageId); }\n getByPlaceholder(p) { return new Locator(\"placeholder\", p, null, this.#pageId); }\n getByTestId(id) { return new Locator(\"testId\", id, null, this.#pageId); }\n getByAltText(alt) { return new Locator(\"altText\", alt, null, this.#pageId); }\n getByTitle(title) { return new Locator(\"title\", title, null, this.#pageId); }\n frameLocator(selector) {\n const pageId = this.#pageId;\n return {\n locator(innerSelector) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"css\", innerSelector, null]]), null, pageId); },\n getByRole(role, options) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"role\", role, options ? JSON.stringify(options) : null]]), null, pageId); },\n getByText(text) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"text\", text, null]]), null, pageId); },\n getByLabel(label) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"label\", label, null]]), null, pageId); },\n getByPlaceholder(placeholder) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"placeholder\", placeholder, null]]), null, pageId); },\n getByTestId(testId) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"testId\", testId, null]]), null, pageId); },\n getByAltText(alt) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"altText\", alt, null]]), null, pageId); },\n getByTitle(title) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"title\", title, null]]), null, pageId); },\n };\n }\n async goBack(options) {\n await __pw_invoke(\"goBack\", [options?.waitUntil || null], { pageId: this.#pageId });\n }\n async goForward(options) {\n await __pw_invoke(\"goForward\", [options?.waitUntil || null], { pageId: this.#pageId });\n }\n async waitForURL(url, options) {\n if (typeof url === 'function') {\n const predicateId = __pw_register_predicate(url);\n try {\n await __pw_invoke(\"waitForURLPredicate\", [predicateId, options?.timeout || null, options?.waitUntil || null], { pageId: this.#pageId });\n } finally {\n __pw_unregister_predicate(predicateId);\n }\n return;\n }\n let serializedUrl;\n if (typeof url === 'string') {\n serializedUrl = { type: 'string', value: url };\n } else if (url && typeof url === 'object' && typeof url.source === 'string' && typeof url.flags === 'string') {\n serializedUrl = { type: 'regex', value: { $regex: url.source, $flags: url.flags } };\n } else {\n serializedUrl = url;\n }\n return __pw_invoke(\"waitForURL\", [serializedUrl, options?.timeout || null, options?.waitUntil || null], { pageId: this.#pageId });\n }\n async waitForRequest(urlOrPredicate, options) {\n if (typeof urlOrPredicate === 'function') {\n const userPredicate = urlOrPredicate;\n const wrappedPredicate = (data) => {\n const requestLike = {\n url: () => data.url,\n method: () => data.method,\n headers: () => Object.fromEntries(data.headers),\n headersArray: () => data.headers.map(h => ({ name: h[0], value: h[1] })),\n postData: () => data.body || null,\n };\n return userPredicate(requestLike);\n };\n const predicateId = __pw_register_predicate(wrappedPredicate);\n const pageId = this.#pageId;\n // Start listening immediately (before the user triggers the request)\n const broadMatcher = { type: 'regex', value: { $regex: '.*', $flags: '' } };\n const startResult = await __pw_invoke(\"waitForRequestStart\", [broadMatcher, options?.timeout || null], { pageId });\n const listenerId = startResult.listenerId;\n try {\n const r = await __pw_invoke(\"waitForRequestPredicateFinish\", [listenerId, predicateId, options?.timeout || null], { pageId });\n return { url: () => r.url, method: () => r.method, headers: () => r.headers, postData: () => r.postData };\n } finally {\n __pw_unregister_predicate(predicateId);\n }\n }\n let serializedMatcher;\n if (typeof urlOrPredicate === 'string') {\n serializedMatcher = { type: 'string', value: urlOrPredicate };\n } else if (urlOrPredicate && typeof urlOrPredicate === 'object'\n && typeof urlOrPredicate.source === 'string'\n && typeof urlOrPredicate.flags === 'string') {\n serializedMatcher = { type: 'regex', value: { $regex: urlOrPredicate.source, $flags: urlOrPredicate.flags } };\n } else {\n throw new Error('waitForRequest requires a URL string, RegExp, or predicate function');\n }\n const startResult = await __pw_invoke(\"waitForRequestStart\", [serializedMatcher, options?.timeout || null], { pageId: this.#pageId });\n const listenerId = startResult.listenerId;\n const pageId = this.#pageId;\n const r = await __pw_invoke(\"waitForRequestFinish\", [listenerId], { pageId });\n return { url: () => r.url, method: () => r.method, headers: () => r.headers, postData: () => r.postData };\n }\n async waitForResponse(urlOrPredicate, options) {\n if (typeof urlOrPredicate === 'function') {\n const userPredicate = urlOrPredicate;\n const wrappedPredicate = (data) => {\n const responseLike = {\n url: () => data.url,\n status: () => data.status,\n statusText: () => data.statusText,\n headers: () => Object.fromEntries(data.headers),\n headersArray: () => data.headers.map(h => ({ name: h[0], value: h[1] })),\n ok: () => data.status >= 200 && data.status < 300,\n };\n return userPredicate(responseLike);\n };\n const predicateId = __pw_register_predicate(wrappedPredicate);\n const pageId = this.#pageId;\n // Start listening immediately (before the user triggers the response)\n const broadMatcher = { type: 'regex', value: { $regex: '.*', $flags: '' } };\n const startResult = await __pw_invoke(\"waitForResponseStart\", [broadMatcher, options?.timeout || null], { pageId });\n const listenerId = startResult.listenerId;\n try {\n const r = await __pw_invoke(\"waitForResponsePredicateFinish\", [listenerId, predicateId, options?.timeout || null], { pageId });\n return {\n url: () => r.url, status: () => r.status, statusText: () => r.statusText,\n headers: () => r.headers, headersArray: () => r.headersArray,\n ok: () => r.ok, json: async () => r.json, text: async () => r.text, body: async () => r.body,\n };\n } finally {\n __pw_unregister_predicate(predicateId);\n }\n }\n let serializedMatcher;\n if (typeof urlOrPredicate === 'string') {\n serializedMatcher = { type: 'string', value: urlOrPredicate };\n } else if (urlOrPredicate && typeof urlOrPredicate === 'object'\n && typeof urlOrPredicate.source === 'string'\n && typeof urlOrPredicate.flags === 'string') {\n serializedMatcher = { type: 'regex', value: { $regex: urlOrPredicate.source, $flags: urlOrPredicate.flags } };\n } else {\n throw new Error('waitForResponse requires a URL string, RegExp, or predicate function');\n }\n const startResult = await __pw_invoke(\"waitForResponseStart\", [serializedMatcher, options?.timeout || null], { pageId: this.#pageId });\n const listenerId = startResult.listenerId;\n const pageId = this.#pageId;\n const r = await __pw_invoke(\"waitForResponseFinish\", [listenerId], { pageId });\n return {\n url: () => r.url, status: () => r.status, statusText: () => r.statusText,\n headers: () => r.headers, headersArray: () => r.headersArray,\n ok: () => r.ok, json: async () => r.json, text: async () => r.text, body: async () => r.body,\n };\n }\n context() {\n const contextId = this.#contextId;\n return new IsolateContext(contextId);\n }\n async click(selector) { return this.locator(selector).click(); }\n async fill(selector, value) { return this.locator(selector).fill(value); }\n async textContent(selector) { return this.locator(selector).textContent(); }\n async innerText(selector) { return this.locator(selector).innerText(); }\n async innerHTML(selector) { return this.locator(selector).innerHTML(); }\n async getAttribute(selector, name) { return this.locator(selector).getAttribute(name); }\n async inputValue(selector) { return this.locator(selector).inputValue(); }\n async isVisible(selector) { return this.locator(selector).isVisible(); }\n async isEnabled(selector) { return this.locator(selector).isEnabled(); }\n async isChecked(selector) { return this.locator(selector).isChecked(); }\n async isHidden(selector) { return this.locator(selector).isHidden(); }\n async isDisabled(selector) { return this.locator(selector).isDisabled(); }\n async screenshot(options) { return __pw_invoke(\"screenshot\", [options || {}], { pageId: this.#pageId }); }\n async setViewportSize(size) { return __pw_invoke(\"setViewportSize\", [size], { pageId: this.#pageId }); }\n async viewportSize() { return __pw_invoke(\"viewportSize\", [], { pageId: this.#pageId }); }\n async emulateMedia(options) { return __pw_invoke(\"emulateMedia\", [options], { pageId: this.#pageId }); }\n async setExtraHTTPHeaders(headers) { return __pw_invoke(\"setExtraHTTPHeaders\", [headers], { pageId: this.#pageId }); }\n async bringToFront() { return __pw_invoke(\"bringToFront\", [], { pageId: this.#pageId }); }\n async close() { return __pw_invoke(\"close\", [], { pageId: this.#pageId }); }\n async isClosed() { return __pw_invoke(\"isClosed\", [], { pageId: this.#pageId }); }\n async pdf(options) { return __pw_invoke(\"pdf\", [options || {}], { pageId: this.#pageId }); }\n async pause() { return __pw_invoke(\"pause\", [], { pageId: this.#pageId }); }\n async frames() { return __pw_invoke(\"frames\", [], { pageId: this.#pageId }); }\n async mainFrame() { return __pw_invoke(\"mainFrame\", [], { pageId: this.#pageId }); }\n get keyboard() {\n const pageId = this.#pageId;\n return {\n async type(text, options) { return __pw_invoke(\"keyboardType\", [text, options], { pageId }); },\n async press(key, options) { return __pw_invoke(\"keyboardPress\", [key, options], { pageId }); },\n async down(key) { return __pw_invoke(\"keyboardDown\", [key], { pageId }); },\n async up(key) { return __pw_invoke(\"keyboardUp\", [key], { pageId }); },\n async insertText(text) { return __pw_invoke(\"keyboardInsertText\", [text], { pageId }); }\n };\n }\n get mouse() {\n const pageId = this.#pageId;\n return {\n async move(x, y, options) { return __pw_invoke(\"mouseMove\", [x, y, options], { pageId }); },\n async click(x, y, options) { return __pw_invoke(\"mouseClick\", [x, y, options], { pageId }); },\n async down(options) { return __pw_invoke(\"mouseDown\", [options], { pageId }); },\n async up(options) { return __pw_invoke(\"mouseUp\", [options], { pageId }); },\n async wheel(deltaX, deltaY) { return __pw_invoke(\"mouseWheel\", [deltaX, deltaY], { pageId }); }\n };\n }\n get request() {\n const pageId = this.#pageId;\n return {\n async fetch(url, options) {\n const result = await __pw_invoke(\"request\", [url, options?.method || \"GET\", options?.data, options?.headers], { pageId });\n return {\n status: () => result.status,\n ok: () => result.ok,\n headers: () => result.headers,\n json: async () => result.json,\n text: async () => result.text,\n body: async () => result.body,\n };\n },\n async get(url, options) { return this.fetch(url, { ...options, method: \"GET\" }); },\n async post(url, options) { return this.fetch(url, { ...options, method: \"POST\" }); },\n async put(url, options) { return this.fetch(url, { ...options, method: \"PUT\" }); },\n async delete(url, options) { return this.fetch(url, { ...options, method: \"DELETE\" }); },\n };\n }\n }\n globalThis.IsolatePage = IsolatePage;\n\n // IsolateContext class - represents a browser context with a specific contextId\n class IsolateContext {\n #contextId;\n constructor(contextId) { this.#contextId = contextId; }\n get __contextId() { return this.#contextId; }\n\n async newPage() {\n const result = await __pw_invoke(\"newPage\", [], { contextId: this.#contextId });\n return new IsolatePage(result.pageId, this.#contextId);\n }\n async close() { return __pw_invoke(\"closeContext\", [], { contextId: this.#contextId }); }\n async clearCookies() { return __pw_invoke(\"clearCookies\", [], { contextId: this.#contextId }); }\n async addCookies(cookies) { return __pw_invoke(\"addCookies\", [cookies], { contextId: this.#contextId }); }\n async cookies(urls) { return __pw_invoke(\"cookies\", [urls], { contextId: this.#contextId }); }\n }\n globalThis.IsolateContext = IsolateContext;\n\n // browser global - for creating new contexts\n globalThis.browser = {\n async newContext(options) {\n const result = await __pw_invoke(\"newContext\", [options || null]);\n return new IsolateContext(result.contextId);\n }\n };\n\n // context global - represents the default context\n globalThis.context = new IsolateContext(\"ctx_0\");\n\n // page global - represents the default page\n globalThis.page = new IsolatePage(\"page_0\", \"ctx_0\");\n})();\n`);\n\n // Locator class with pageId support\n context.evalSync(`\n(function() {\n // Helper to serialize options including RegExp\n function serializeOptions(options) {\n if (!options) return null;\n const serialized = { ...options };\n if (options.name && typeof options.name === 'object' && typeof options.name.source === 'string' && typeof options.name.flags === 'string') {\n serialized.name = { $regex: options.name.source, $flags: options.name.flags };\n }\n return JSON.stringify(serialized);\n }\n\n const INPUT_FILES_VALIDATION_ERROR =\n \"setInputFiles() expects a file path string, an array of file path strings, \" +\n \"a single inline file object ({ name, mimeType, buffer }), or an array of inline file objects.\";\n\n function isInlineFileObject(value) {\n return !!value\n && typeof value === 'object'\n && typeof value.name === 'string'\n && typeof value.mimeType === 'string'\n && 'buffer' in value;\n }\n\n function encodeInlineFileBuffer(buffer) {\n if (typeof buffer === 'string') {\n return buffer;\n }\n let bytes;\n if (buffer instanceof ArrayBuffer) {\n bytes = new Uint8Array(buffer);\n } else if (ArrayBuffer.isView(buffer)) {\n bytes = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n } else {\n throw new Error(\n \"setInputFiles() inline file buffer must be a base64 string, ArrayBuffer, or TypedArray.\"\n );\n }\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n }\n\n function serializeInlineFile(file) {\n return {\n name: file.name,\n mimeType: file.mimeType,\n buffer: encodeInlineFileBuffer(file.buffer),\n };\n }\n\n function normalizeSetInputFilesArg(files) {\n if (typeof files === 'string') {\n return files;\n }\n if (isInlineFileObject(files)) {\n return serializeInlineFile(files);\n }\n if (!Array.isArray(files)) {\n throw new Error(INPUT_FILES_VALIDATION_ERROR);\n }\n if (files.length === 0) {\n return [];\n }\n\n let hasPaths = false;\n let hasInline = false;\n const inlineFiles = [];\n\n for (const file of files) {\n if (typeof file === 'string') {\n hasPaths = true;\n continue;\n }\n if (isInlineFileObject(file)) {\n hasInline = true;\n inlineFiles.push(serializeInlineFile(file));\n continue;\n }\n throw new Error(INPUT_FILES_VALIDATION_ERROR);\n }\n\n if (hasPaths && hasInline) {\n throw new Error(\n \"setInputFiles() does not support mixing file paths and inline file objects in the same array.\"\n );\n }\n return hasInline ? inlineFiles : files;\n }\n\n class Locator {\n #type; #value; #options; #pageId;\n constructor(type, value, options, pageId) {\n this.#type = type;\n this.#value = value;\n this.#options = options;\n this.#pageId = pageId || \"page_0\";\n }\n\n _getInfo() { return [this.#type, this.#value, this.#options]; }\n _getPageId() { return this.#pageId; }\n\n // Helper to create a chained locator\n _chain(childType, childValue, childOptions) {\n const parentInfo = this._getInfo();\n const childInfo = [childType, childValue, childOptions];\n return new Locator(\"chained\", JSON.stringify([parentInfo, childInfo]), null, this.#pageId);\n }\n\n async click() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"click\", null], { pageId: this.#pageId });\n }\n async dblclick() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"dblclick\", null], { pageId: this.#pageId });\n }\n async fill(text) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"fill\", text], { pageId: this.#pageId });\n }\n async type(text) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"type\", text], { pageId: this.#pageId });\n }\n async check() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"check\", null], { pageId: this.#pageId });\n }\n async uncheck() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"uncheck\", null], { pageId: this.#pageId });\n }\n async selectOption(value) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"selectOption\", value], { pageId: this.#pageId });\n }\n async clear() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"clear\", null], { pageId: this.#pageId });\n }\n async press(key) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"press\", key], { pageId: this.#pageId });\n }\n async hover() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"hover\", null], { pageId: this.#pageId });\n }\n async focus() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"focus\", null], { pageId: this.#pageId });\n }\n async textContent() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"getText\", null], { pageId: this.#pageId });\n }\n async inputValue() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"getValue\", null], { pageId: this.#pageId });\n }\n async isVisible() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isVisible\", null], { pageId: this.#pageId });\n }\n async isEnabled() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isEnabled\", null], { pageId: this.#pageId });\n }\n async isChecked() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isChecked\", null], { pageId: this.#pageId });\n }\n async count() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"count\", null], { pageId: this.#pageId });\n }\n async getAttribute(name) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"getAttribute\", name], { pageId: this.#pageId });\n }\n async isDisabled() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isDisabled\", null], { pageId: this.#pageId });\n }\n async isHidden() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isHidden\", null], { pageId: this.#pageId });\n }\n async innerHTML() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"innerHTML\", null], { pageId: this.#pageId });\n }\n async innerText() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"innerText\", null], { pageId: this.#pageId });\n }\n async allTextContents() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"allTextContents\", null], { pageId: this.#pageId });\n }\n async allInnerTexts() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"allInnerTexts\", null], { pageId: this.#pageId });\n }\n async waitFor(options) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"waitFor\", options || {}], { pageId: this.#pageId });\n }\n async boundingBox() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"boundingBox\", null], { pageId: this.#pageId });\n }\n async setInputFiles(files) {\n const serializedFiles = normalizeSetInputFilesArg(files);\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"setInputFiles\", serializedFiles], { pageId: this.#pageId });\n }\n async screenshot(options) {\n const base64 = await __pw_invoke(\"locatorAction\", [...this._getInfo(), \"screenshot\", options || {}], { pageId: this.#pageId });\n return base64;\n }\n async dragTo(target) {\n const targetInfo = target._getInfo();\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"dragTo\", targetInfo], { pageId: this.#pageId });\n }\n async scrollIntoViewIfNeeded() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"scrollIntoViewIfNeeded\", null], { pageId: this.#pageId });\n }\n async highlight() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"highlight\", null], { pageId: this.#pageId });\n }\n async evaluate(fn, arg) {\n const fnString = typeof fn === 'function' ? fn.toString() : fn;\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"evaluate\", [fnString, arg]], { pageId: this.#pageId });\n }\n async evaluateAll(fn, arg) {\n const fnString = typeof fn === 'function' ? fn.toString() : fn;\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"evaluateAll\", [fnString, arg]], { pageId: this.#pageId });\n }\n locator(selector) {\n return this._chain(\"css\", selector, null);\n }\n // Chaining: getBy* methods within a locator\n getByRole(role, options) {\n return this._chain(\"role\", role, serializeOptions(options));\n }\n getByText(text) {\n return this._chain(\"text\", text, null);\n }\n getByLabel(label) {\n return this._chain(\"label\", label, null);\n }\n getByPlaceholder(placeholder) {\n return this._chain(\"placeholder\", placeholder, null);\n }\n getByTestId(testId) {\n return this._chain(\"testId\", testId, null);\n }\n getByAltText(altText) {\n return this._chain(\"altText\", altText, null);\n }\n getByTitle(title) {\n return this._chain(\"title\", title, null);\n }\n async all() {\n const n = await this.count();\n const result = [];\n for (let i = 0; i < n; i++) {\n result.push(this.nth(i));\n }\n return result;\n }\n nth(index) {\n const existingOpts = this.#options ? JSON.parse(this.#options) : {};\n return new Locator(this.#type, this.#value, JSON.stringify({ ...existingOpts, nth: index }), this.#pageId);\n }\n first() {\n return this.nth(0);\n }\n last() {\n return this.nth(-1);\n }\n filter(options) {\n const existingOpts = this.#options ? JSON.parse(this.#options) : {};\n const serializedFilter = { ...options };\n // Use duck-typing RegExp detection (instanceof fails across isolated-vm boundary)\n const hasText = options.hasText;\n if (hasText && typeof hasText === 'object' && typeof hasText.source === 'string' && typeof hasText.flags === 'string') {\n serializedFilter.hasText = { $regex: hasText.source, $flags: hasText.flags };\n }\n const hasNotText = options.hasNotText;\n if (hasNotText && typeof hasNotText === 'object' && typeof hasNotText.source === 'string' && typeof hasNotText.flags === 'string') {\n serializedFilter.hasNotText = { $regex: hasNotText.source, $flags: hasNotText.flags };\n }\n // Serialize has/hasNot locators using duck-typing\n const has = options.has;\n if (has && typeof has === 'object' && typeof has._getInfo === 'function') {\n serializedFilter.has = { $locator: has._getInfo() };\n }\n const hasNot = options.hasNot;\n if (hasNot && typeof hasNot === 'object' && typeof hasNot._getInfo === 'function') {\n serializedFilter.hasNot = { $locator: hasNot._getInfo() };\n }\n return new Locator(this.#type, this.#value, JSON.stringify({ ...existingOpts, filter: serializedFilter }), this.#pageId);\n }\n or(other) {\n // Create a composite locator that matches either this or other\n const thisInfo = this._getInfo();\n const otherInfo = other._getInfo();\n return new Locator(\"or\", JSON.stringify([thisInfo, otherInfo]), null, this.#pageId);\n }\n and(other) {\n // Create a composite locator that matches both this and other\n const thisInfo = this._getInfo();\n const otherInfo = other._getInfo();\n return new Locator(\"and\", JSON.stringify([thisInfo, otherInfo]), null, this.#pageId);\n }\n }\n globalThis.Locator = Locator;\n})();\n`);\n\n // Extend expect with locator matchers (only if test-environment already defined expect)\n context.evalSync(`\n(function() {\n // Helper to create locator matchers\n function createLocatorMatchers(locator, baseMatchers) {\n const info = locator._getInfo();\n const pageId = locator._getPageId ? locator._getPageId() : \"page_0\";\n\n // Helper for serializing regex values\n function serializeExpected(expected) {\n if (expected instanceof RegExp) {\n return { $regex: expected.source, $flags: expected.flags };\n }\n return expected;\n }\n\n const locatorMatchers = {\n async toBeVisible(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeVisible\", null, false, options?.timeout], { pageId });\n },\n async toContainText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainText\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveValue(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveValue\", expected, false, options?.timeout], { pageId });\n },\n async toBeEnabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEnabled\", null, false, options?.timeout], { pageId });\n },\n async toBeChecked(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeChecked\", null, false, options?.timeout], { pageId });\n },\n async toHaveAttribute(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAttribute\", { name, value: serializeExpected(value) }, false, options?.timeout], { pageId });\n },\n async toHaveText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveText\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveCount(count, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCount\", count, false, options?.timeout], { pageId });\n },\n async toBeHidden(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeHidden\", null, false, options?.timeout], { pageId });\n },\n async toBeDisabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeDisabled\", null, false, options?.timeout], { pageId });\n },\n async toBeFocused(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeFocused\", null, false, options?.timeout], { pageId });\n },\n async toBeEmpty(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEmpty\", null, false, options?.timeout], { pageId });\n },\n // New matchers\n async toBeAttached(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeAttached\", null, false, options?.timeout], { pageId });\n },\n async toBeEditable(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEditable\", null, false, options?.timeout], { pageId });\n },\n async toHaveClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveClass\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toContainClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainClass\", expected, false, options?.timeout], { pageId });\n },\n async toHaveId(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveId\", expected, false, options?.timeout], { pageId });\n },\n async toBeInViewport(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeInViewport\", null, false, options?.timeout], { pageId });\n },\n async toHaveCSS(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCSS\", { name, value: serializeExpected(value) }, false, options?.timeout], { pageId });\n },\n async toHaveJSProperty(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveJSProperty\", { name, value }, false, options?.timeout], { pageId });\n },\n async toHaveAccessibleName(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleName\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveAccessibleDescription(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleDescription\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveRole(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveRole\", expected, false, options?.timeout], { pageId });\n },\n not: {\n async toBeVisible(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeVisible\", null, true, options?.timeout], { pageId });\n },\n async toContainText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainText\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveValue(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveValue\", expected, true, options?.timeout], { pageId });\n },\n async toBeEnabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEnabled\", null, true, options?.timeout], { pageId });\n },\n async toBeChecked(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeChecked\", null, true, options?.timeout], { pageId });\n },\n async toHaveAttribute(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAttribute\", { name, value: serializeExpected(value) }, true, options?.timeout], { pageId });\n },\n async toHaveText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveText\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveCount(count, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCount\", count, true, options?.timeout], { pageId });\n },\n async toBeHidden(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeHidden\", null, true, options?.timeout], { pageId });\n },\n async toBeDisabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeDisabled\", null, true, options?.timeout], { pageId });\n },\n async toBeFocused(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeFocused\", null, true, options?.timeout], { pageId });\n },\n async toBeEmpty(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEmpty\", null, true, options?.timeout], { pageId });\n },\n // New negated matchers\n async toBeAttached(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeAttached\", null, true, options?.timeout], { pageId });\n },\n async toBeEditable(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEditable\", null, true, options?.timeout], { pageId });\n },\n async toHaveClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveClass\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toContainClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainClass\", expected, true, options?.timeout], { pageId });\n },\n async toHaveId(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveId\", expected, true, options?.timeout], { pageId });\n },\n async toBeInViewport(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeInViewport\", null, true, options?.timeout], { pageId });\n },\n async toHaveCSS(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCSS\", { name, value: serializeExpected(value) }, true, options?.timeout], { pageId });\n },\n async toHaveJSProperty(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveJSProperty\", { name, value }, true, options?.timeout], { pageId });\n },\n async toHaveAccessibleName(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleName\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveAccessibleDescription(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleDescription\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveRole(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveRole\", expected, true, options?.timeout], { pageId });\n },\n }\n };\n\n // Merge locator matchers with base matchers from test-environment\n if (baseMatchers) {\n return {\n ...baseMatchers,\n ...locatorMatchers,\n not: { ...baseMatchers.not, ...locatorMatchers.not }\n };\n }\n return locatorMatchers;\n }\n\n // Helper to create page matchers\n function createPageMatchers(page, baseMatchers) {\n const pageId = page.__pageId || \"page_0\";\n\n function serializeExpected(expected) {\n if (expected instanceof RegExp) {\n return { $regex: expected.source, $flags: expected.flags };\n }\n return expected;\n }\n\n const pageMatchers = {\n async toHaveURL(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveURL\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveTitle(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveTitle\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n not: {\n async toHaveURL(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveURL\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveTitle(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveTitle\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n }\n };\n\n if (baseMatchers) {\n return {\n ...baseMatchers,\n ...pageMatchers,\n not: { ...baseMatchers.not, ...pageMatchers.not }\n };\n }\n return pageMatchers;\n }\n\n // Only extend expect if test-environment already defined it\n if (typeof globalThis.expect === 'function') {\n const originalExpect = globalThis.expect;\n globalThis.expect = function(actual) {\n const baseMatchers = originalExpect(actual);\n // If actual is a Locator, add locator-specific matchers\n if (actual && actual.constructor && actual.constructor.name === 'Locator') {\n return createLocatorMatchers(actual, baseMatchers);\n }\n // If actual is the page object (IsolatePage), add page-specific matchers\n if (actual && actual.__isPage === true) {\n return createPageMatchers(actual, baseMatchers);\n }\n return baseMatchers;\n };\n }\n // If test-environment not loaded, expect remains undefined\n})();\n`);\n\n // ========================================================================\n // Return Handle\n // ========================================================================\n\n return {\n dispose() {\n // Only remove listeners if page was provided directly\n if (page && requestHandler && responseHandler && requestFailedHandler && consoleHandler && pageErrorHandler) {\n page.off(\"request\", requestHandler);\n page.off(\"response\", responseHandler);\n page.off(\"requestfailed\", requestFailedHandler);\n page.off(\"console\", consoleHandler);\n page.off(\"pageerror\", pageErrorHandler);\n }\n browserConsoleLogs.length = 0;\n pageErrors.length = 0;\n networkRequests.length = 0;\n networkResponses.length = 0;\n requestFailures.length = 0;\n },\n getBrowserConsoleLogs() {\n return [...browserConsoleLogs];\n },\n getPageErrors() {\n return [...pageErrors];\n },\n getNetworkRequests() {\n return [...networkRequests];\n },\n getNetworkResponses() {\n return [...networkResponses];\n },\n getRequestFailures() {\n return [...requestFailures];\n },\n clearCollected() {\n browserConsoleLogs.length = 0;\n pageErrors.length = 0;\n networkRequests.length = 0;\n networkResponses.length = 0;\n requestFailures.length = 0;\n },\n };\n}\n"
|
|
5
|
+
"import ivm from \"@ricsam/isolated-vm\";\nimport type {\n PlaywrightOperation,\n} from \"../protocol/index.mjs\";\nimport {\n DEFAULT_PLAYWRIGHT_HANDLER_META,\n} from \"./types.mjs\";\n\n// Re-export handler functions from handler.ts\nexport {\n createPlaywrightHandler,\n defaultPlaywrightHandler,\n getDefaultPlaywrightHandlerMetadata,\n} from \"./handler.mjs\";\n\n// Re-export protocol types\nexport type { PlaywrightOperation, PlaywrightResult, PlaywrightEvent, PlaywrightFileData } from \"../protocol/index.mjs\";\nexport { DEFAULT_PLAYWRIGHT_HANDLER_META };\n\n// Re-export types from types.ts\nexport type {\n NetworkRequestInfo,\n NetworkResponseInfo,\n BrowserConsoleLogEntry,\n PageErrorInfo,\n RequestFailureInfo,\n PlaywrightCallback,\n PlaywrightSetupOptions,\n PlaywrightHandle,\n} from \"./types.mjs\";\n\n// Import handler functions for use within this module\nimport {\n createPlaywrightHandler,\n getDefaultPlaywrightHandlerMetadata,\n} from \"./handler.mjs\";\nimport type {\n PlaywrightCallback,\n PlaywrightSetupOptions,\n PlaywrightHandle,\n NetworkRequestInfo,\n NetworkResponseInfo,\n BrowserConsoleLogEntry,\n PageErrorInfo,\n RequestFailureInfo,\n} from \"./types.mjs\";\n\n// ============================================================================\n// Predicate Support Wrapper for Remote Handlers\n// ============================================================================\n\n/**\n * Wraps a remote handler (no direct page access) to support predicate-based\n * waitFor* operations. Predicate ops are handled locally by issuing sub-operations\n * through the handler and evaluating the predicate in the isolate.\n */\nfunction wrapHandlerWithPredicateSupport(\n handler: PlaywrightCallback,\n evaluatePredicate: (predicateId: number, data: unknown) => boolean,\n defaultTimeout: number,\n): PlaywrightCallback {\n return async (op) => {\n switch (op.type) {\n case \"waitForURLPredicate\": {\n const [predicateId, customTimeout, waitUntil] = op.args as [number, number?, string?];\n const effectiveTimeout = customTimeout ?? defaultTimeout;\n const startTime = Date.now();\n const pollInterval = 100;\n\n while (true) {\n // Get current URL via the handler\n const urlResult = await handler({ type: \"url\", args: [], pageId: op.pageId, contextId: op.contextId });\n if (urlResult.ok) {\n try {\n if (evaluatePredicate(predicateId, urlResult.value as string)) {\n return { ok: true };\n }\n } catch (e) {\n const error = e as Error;\n return { ok: false, error: { name: error.name, message: error.message } };\n }\n }\n if (effectiveTimeout > 0 && Date.now() - startTime >= effectiveTimeout) {\n return { ok: false, error: { name: \"Error\", message: `Timeout ${effectiveTimeout}ms exceeded waiting for URL` } };\n }\n await new Promise(r => setTimeout(r, pollInterval));\n }\n }\n case \"waitForResponsePredicateFinish\": {\n const [initialListenerId, predicateId, customTimeout] = op.args as [string, number, number?];\n const effectiveTimeout = customTimeout ?? defaultTimeout;\n const broadMatcher = { type: 'regex' as const, value: { $regex: '.*', $flags: '' } };\n const startTime = Date.now();\n let currentListenerId = initialListenerId;\n\n while (true) {\n // Wait for response data from current listener\n const finishResult = await handler({\n type: \"waitForResponseFinish\",\n args: [currentListenerId],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!finishResult.ok) return finishResult;\n const responseData = finishResult.value as Record<string, unknown>;\n\n // Evaluate predicate\n try {\n const serialized = {\n method: '',\n headers: Object.entries((responseData.headers || {}) as Record<string, string>),\n url: responseData.url as string,\n status: responseData.status as number,\n statusText: responseData.statusText as string,\n body: (responseData.text as string) || '',\n };\n if (evaluatePredicate(predicateId, serialized)) {\n return finishResult;\n }\n } catch (e) {\n const error = e as Error;\n return { ok: false, error: { name: error.name, message: error.message } };\n }\n\n if (effectiveTimeout > 0 && Date.now() - startTime >= effectiveTimeout) {\n return { ok: false, error: { name: \"Error\", message: `Timeout ${effectiveTimeout}ms exceeded waiting for response` } };\n }\n\n // Not matched — start next listener\n const remainingTimeout = effectiveTimeout > 0 ? Math.max(1, effectiveTimeout - (Date.now() - startTime)) : effectiveTimeout;\n const nextStartResult = await handler({\n type: \"waitForResponseStart\",\n args: [broadMatcher, remainingTimeout],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!nextStartResult.ok) return nextStartResult;\n currentListenerId = (nextStartResult.value as { listenerId: string }).listenerId;\n }\n }\n case \"waitForRequestPredicateFinish\": {\n const [initialListenerId, predicateId, customTimeout] = op.args as [string, number, number?];\n const effectiveTimeout = customTimeout ?? defaultTimeout;\n const broadMatcher = { type: 'regex' as const, value: { $regex: '.*', $flags: '' } };\n const startTime = Date.now();\n let currentListenerId = initialListenerId;\n\n while (true) {\n const finishResult = await handler({\n type: \"waitForRequestFinish\",\n args: [currentListenerId],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!finishResult.ok) return finishResult;\n const requestData = finishResult.value as Record<string, unknown>;\n\n try {\n const serialized = {\n method: requestData.method as string,\n headers: Object.entries((requestData.headers || {}) as Record<string, string>),\n url: requestData.url as string,\n body: (requestData.postData as string) || '',\n };\n if (evaluatePredicate(predicateId, serialized)) {\n return finishResult;\n }\n } catch (e) {\n const error = e as Error;\n return { ok: false, error: { name: error.name, message: error.message } };\n }\n\n if (effectiveTimeout > 0 && Date.now() - startTime >= effectiveTimeout) {\n return { ok: false, error: { name: \"Error\", message: `Timeout ${effectiveTimeout}ms exceeded waiting for request` } };\n }\n\n // Not matched — start next listener\n const remainingTimeout = effectiveTimeout > 0 ? Math.max(1, effectiveTimeout - (Date.now() - startTime)) : effectiveTimeout;\n const nextStartResult = await handler({\n type: \"waitForRequestStart\",\n args: [broadMatcher, remainingTimeout],\n pageId: op.pageId,\n contextId: op.contextId,\n });\n if (!nextStartResult.ok) return nextStartResult;\n currentListenerId = (nextStartResult.value as { listenerId: string }).listenerId;\n }\n }\n default:\n return handler(op);\n }\n };\n}\n\n// ============================================================================\n// Setup Playwright\n// ============================================================================\n\n/**\n * Set up playwright in an isolate context.\n *\n * For local use: provide `page` option (direct page access)\n * For remote use: provide `handler` option (callback pattern)\n */\nexport async function setupPlaywright(\n context: ivm.Context,\n options: PlaywrightSetupOptions\n): Promise<PlaywrightHandle> {\n const timeout = options.timeout ?? 30000;\n\n // Determine if we have a page or handler.\n // Handlers created via defaultPlaywrightHandler() carry page metadata so\n // event capture/collected data keeps working in handler-first mode.\n const explicitPage = \"page\" in options ? options.page : undefined;\n const handler = \"handler\" in options ? options.handler : undefined;\n const handlerMetadata = handler\n ? getDefaultPlaywrightHandlerMetadata(handler)\n : undefined;\n const page = explicitPage ?? handlerMetadata?.page;\n\n // Get lifecycle callbacks\n const createPage = \"createPage\" in options ? options.createPage : undefined;\n const createContext = \"createContext\" in options ? options.createContext : undefined;\n const readFile = \"readFile\" in options ? options.readFile : undefined;\n const writeFile = \"writeFile\" in options ? options.writeFile : undefined;\n\n if (!handler && !page) {\n throw new Error(\"Either page or handler must be provided to setupPlaywright\");\n }\n\n // State for collected data (only used when page is provided directly)\n const browserConsoleLogs: BrowserConsoleLogEntry[] = [];\n const pageErrors: PageErrorInfo[] = [];\n const networkRequests: NetworkRequestInfo[] = [];\n const networkResponses: NetworkResponseInfo[] = [];\n const requestFailures: RequestFailureInfo[] = [];\n\n const global = context.global;\n\n // ========================================================================\n // Event Capture (only when page is provided directly)\n // ========================================================================\n\n let requestHandler: ((request: import(\"playwright\").Request) => void) | undefined;\n let responseHandler: ((response: import(\"playwright\").Response) => void) | undefined;\n let requestFailedHandler: ((request: import(\"playwright\").Request) => void) | undefined;\n let consoleHandler: ((msg: import(\"playwright\").ConsoleMessage) => void) | undefined;\n let pageErrorHandler: ((error: Error) => void) | undefined;\n\n if (page) {\n // Get onEvent callback if provided\n const onEvent = \"onEvent\" in options ? options.onEvent : undefined;\n const requestIds = new WeakMap<import(\"playwright\").Request, string>();\n let nextRequestId = 1;\n const getRequestId = (request: import(\"playwright\").Request): string => {\n let requestId = requestIds.get(request);\n if (!requestId) {\n requestId = `req_${nextRequestId++}`;\n requestIds.set(request, requestId);\n }\n return requestId;\n };\n const toLocation = (\n location: { url?: string; lineNumber?: number; columnNumber?: number } | undefined,\n ): BrowserConsoleLogEntry[\"location\"] => {\n if (!location || (!location.url && location.lineNumber == null && location.columnNumber == null)) {\n return undefined;\n }\n\n return {\n url: location.url || undefined,\n lineNumber: location.lineNumber != null ? location.lineNumber + 1 : undefined,\n columnNumber: location.columnNumber != null ? location.columnNumber + 1 : undefined,\n };\n };\n\n requestHandler = (request: import(\"playwright\").Request) => {\n const info: NetworkRequestInfo = {\n requestId: getRequestId(request),\n url: request.url(),\n method: request.method(),\n headers: request.headers(),\n postData: request.postData() ?? undefined,\n resourceType: request.resourceType(),\n timestamp: Date.now(),\n };\n networkRequests.push(info);\n\n if (onEvent) {\n onEvent({\n type: \"networkRequest\",\n requestId: info.requestId,\n url: info.url,\n method: info.method,\n headers: info.headers,\n postData: info.postData,\n resourceType: info.resourceType,\n timestamp: info.timestamp,\n });\n }\n };\n\n responseHandler = (response: import(\"playwright\").Response) => {\n const request = response.request();\n const info: NetworkResponseInfo = {\n requestId: getRequestId(request),\n url: response.url(),\n status: response.status(),\n statusText: response.statusText(),\n headers: response.headers(),\n resourceType: request.resourceType(),\n timestamp: Date.now(),\n };\n networkResponses.push(info);\n\n if (onEvent) {\n onEvent({\n type: \"networkResponse\",\n requestId: info.requestId,\n url: info.url,\n status: info.status,\n statusText: info.statusText,\n headers: info.headers,\n resourceType: info.resourceType,\n timestamp: info.timestamp,\n });\n }\n };\n\n requestFailedHandler = (request: import(\"playwright\").Request) => {\n const info: RequestFailureInfo = {\n requestId: getRequestId(request),\n url: request.url(),\n method: request.method(),\n failureText: request.failure()?.errorText || \"request failed\",\n resourceType: request.resourceType(),\n timestamp: Date.now(),\n };\n requestFailures.push(info);\n\n if (onEvent) {\n onEvent({\n type: \"requestFailure\",\n requestId: info.requestId,\n url: info.url,\n method: info.method,\n failureText: info.failureText,\n resourceType: info.resourceType,\n timestamp: info.timestamp,\n });\n }\n };\n\n consoleHandler = (msg: import(\"playwright\").ConsoleMessage) => {\n const args = msg.args().map((arg) => String(arg));\n const entry: BrowserConsoleLogEntry = {\n level: msg.type(),\n stdout: args.join(\" \"),\n location: toLocation(msg.location()),\n timestamp: Date.now(),\n };\n browserConsoleLogs.push(entry);\n\n if (onEvent) {\n onEvent({\n type: \"browserConsoleLog\",\n level: entry.level,\n stdout: entry.stdout,\n location: entry.location,\n timestamp: entry.timestamp,\n });\n }\n\n // Print to stdout if console option is true\n if (\"console\" in options && options.console) {\n const prefix = `[browser:${entry.level}]`;\n console.log(prefix, entry.stdout);\n }\n };\n\n pageErrorHandler = (error: Error) => {\n const entry: PageErrorInfo = {\n name: error.name,\n message: error.message,\n stack: error.stack,\n timestamp: Date.now(),\n };\n pageErrors.push(entry);\n\n if (onEvent) {\n onEvent({\n type: \"pageError\",\n name: entry.name,\n message: entry.message,\n stack: entry.stack,\n timestamp: entry.timestamp,\n });\n }\n };\n\n page.on(\"request\", requestHandler);\n page.on(\"response\", responseHandler);\n page.on(\"requestfailed\", requestFailedHandler);\n page.on(\"console\", consoleHandler);\n page.on(\"pageerror\", pageErrorHandler);\n }\n\n // ========================================================================\n // Injected JavaScript\n // ========================================================================\n\n // Helper function to invoke handler and handle errors\n context.evalSync(`\n(function() {\n globalThis.__pw_invoke = async function(type, args, options) {\n const op = JSON.stringify({ type, args, pageId: options?.pageId, contextId: options?.contextId });\n const resultJson = await __Playwright_handler_ref.apply(\n undefined,\n [op],\n { result: { promise: true, copy: true } }\n );\n const result = JSON.parse(resultJson);\n if (result.ok) {\n return result.value;\n }\n const error = new Error(result.error.message);\n error.name = result.error.name;\n throw error;\n };\n})();\n`);\n\n // Predicate registry for waitForURL/Request/Response with function predicates\n context.evalSync(`\n(function() {\n const __pw_predicates = new Map();\n let __pw_next_id = 0;\n globalThis.__pw_register_predicate = function(fn) {\n const id = __pw_next_id++;\n __pw_predicates.set(id, fn);\n return id;\n };\n globalThis.__pw_unregister_predicate = function(id) {\n __pw_predicates.delete(id);\n };\n globalThis.__pw_evaluate_predicate = function(id, data) {\n const fn = __pw_predicates.get(id);\n if (!fn) throw new Error('Predicate not found: ' + id);\n const result = fn(data);\n if (result && typeof result === 'object' && typeof result.then === 'function') {\n throw new Error('Async predicates are not supported. Use a synchronous predicate function.');\n }\n return !!result;\n };\n})();\n`);\n\n // Get reference to the predicate evaluation function for host-side use\n const evaluatePredicateRef = context.global.getSync(\n '__pw_evaluate_predicate', { reference: true }\n ) as ivm.Reference<(id: number, data: unknown) => boolean>;\n\n // ========================================================================\n // Create Handler and Unified Handler Reference\n // ========================================================================\n\n const evaluatePredicateFn = (predicateId: number, data: unknown): boolean => {\n return evaluatePredicateRef.applySync(\n undefined,\n [new ivm.ExternalCopy(predicateId).copyInto(), new ivm.ExternalCopy(data).copyInto()]\n ) as boolean;\n };\n\n // Create handler with evaluatePredicate support.\n // When a page is available (either directly or through handler metadata),\n // create a handler with evaluatePredicate for efficient event-based predicate evaluation.\n // When only a remote handler is available (no page), wrap it to intercept predicate\n // operations and implement them via polling/sub-operations.\n let effectiveHandler: PlaywrightCallback;\n if (handler && handlerMetadata?.page) {\n // Handler-first mode with page metadata — recreate with evaluatePredicate\n effectiveHandler = createPlaywrightHandler(handlerMetadata.page, {\n ...handlerMetadata.options,\n evaluatePredicate: evaluatePredicateFn,\n });\n } else if (handler) {\n // Remote handler without page — wrap to handle predicate ops locally\n effectiveHandler = wrapHandlerWithPredicateSupport(handler, evaluatePredicateFn, timeout);\n } else if (page) {\n effectiveHandler = createPlaywrightHandler(page, {\n timeout,\n readFile,\n writeFile,\n createPage,\n createContext,\n evaluatePredicate: evaluatePredicateFn,\n });\n } else {\n throw new Error(\"Either page or handler must be provided to setupPlaywright\");\n }\n\n // Single handler reference that receives operation objects\n global.setSync(\n \"__Playwright_handler_ref\",\n new ivm.Reference(async (opJson: string): Promise<string> => {\n const op = JSON.parse(opJson) as PlaywrightOperation;\n const result = await effectiveHandler(op);\n return JSON.stringify(result);\n })\n );\n\n // IsolatePage class and page/context/browser globals\n context.evalSync(`\n(function() {\n // IsolatePage class - represents a page with a specific pageId\n class IsolatePage {\n #pageId; #contextId;\n constructor(pageId, contextId) {\n this.#pageId = pageId;\n this.#contextId = contextId;\n }\n get __isPage() { return true; }\n get __pageId() { return this.#pageId; }\n get __contextId() { return this.#contextId; }\n\n async goto(url, options) {\n await __pw_invoke(\"goto\", [url, options?.waitUntil || null], { pageId: this.#pageId });\n }\n async reload() {\n await __pw_invoke(\"reload\", [], { pageId: this.#pageId });\n }\n async url() { return __pw_invoke(\"url\", [], { pageId: this.#pageId }); }\n async title() { return __pw_invoke(\"title\", [], { pageId: this.#pageId }); }\n async content() { return __pw_invoke(\"content\", [], { pageId: this.#pageId }); }\n async waitForSelector(selector, options) {\n return __pw_invoke(\"waitForSelector\", [selector, options ? JSON.stringify(options) : null], { pageId: this.#pageId });\n }\n async waitForTimeout(ms) { return __pw_invoke(\"waitForTimeout\", [ms], { pageId: this.#pageId }); }\n async waitForLoadState(state) { return __pw_invoke(\"waitForLoadState\", [state || null], { pageId: this.#pageId }); }\n async evaluate(script, arg) {\n const hasArg = arguments.length > 1;\n if (hasArg) {\n const serialized = typeof script === \"function\" ? script.toString() : script;\n return __pw_invoke(\"evaluate\", [serialized, arg], { pageId: this.#pageId });\n }\n const serialized = typeof script === \"function\" ? \"(\" + script.toString() + \")()\" : script;\n return __pw_invoke(\"evaluate\", [serialized], { pageId: this.#pageId });\n }\n locator(selector) { return new Locator(\"css\", selector, null, this.#pageId); }\n getByRole(role, options) {\n if (options) {\n const serialized = { ...options };\n const name = options.name;\n if (name && typeof name === 'object' && typeof name.source === 'string' && typeof name.flags === 'string') {\n serialized.name = { $regex: name.source, $flags: name.flags };\n }\n return new Locator(\"role\", role, JSON.stringify(serialized), this.#pageId);\n }\n return new Locator(\"role\", role, null, this.#pageId);\n }\n getByText(text) { return new Locator(\"text\", text, null, this.#pageId); }\n getByLabel(label) { return new Locator(\"label\", label, null, this.#pageId); }\n getByPlaceholder(p) { return new Locator(\"placeholder\", p, null, this.#pageId); }\n getByTestId(id) { return new Locator(\"testId\", id, null, this.#pageId); }\n getByAltText(alt) { return new Locator(\"altText\", alt, null, this.#pageId); }\n getByTitle(title) { return new Locator(\"title\", title, null, this.#pageId); }\n frameLocator(selector) {\n const pageId = this.#pageId;\n return {\n locator(innerSelector) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"css\", innerSelector, null]]), null, pageId); },\n getByRole(role, options) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"role\", role, options ? JSON.stringify(options) : null]]), null, pageId); },\n getByText(text) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"text\", text, null]]), null, pageId); },\n getByLabel(label) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"label\", label, null]]), null, pageId); },\n getByPlaceholder(placeholder) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"placeholder\", placeholder, null]]), null, pageId); },\n getByTestId(testId) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"testId\", testId, null]]), null, pageId); },\n getByAltText(alt) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"altText\", alt, null]]), null, pageId); },\n getByTitle(title) { return new Locator(\"frame\", JSON.stringify([[\"css\", selector, null], [\"title\", title, null]]), null, pageId); },\n };\n }\n async goBack(options) {\n await __pw_invoke(\"goBack\", [options?.waitUntil || null], { pageId: this.#pageId });\n }\n async goForward(options) {\n await __pw_invoke(\"goForward\", [options?.waitUntil || null], { pageId: this.#pageId });\n }\n async waitForURL(url, options) {\n if (typeof url === 'function') {\n const predicateId = __pw_register_predicate(url);\n try {\n await __pw_invoke(\"waitForURLPredicate\", [predicateId, options?.timeout || null, options?.waitUntil || null], { pageId: this.#pageId });\n } finally {\n __pw_unregister_predicate(predicateId);\n }\n return;\n }\n let serializedUrl;\n if (typeof url === 'string') {\n serializedUrl = { type: 'string', value: url };\n } else if (url && typeof url === 'object' && typeof url.source === 'string' && typeof url.flags === 'string') {\n serializedUrl = { type: 'regex', value: { $regex: url.source, $flags: url.flags } };\n } else {\n serializedUrl = url;\n }\n return __pw_invoke(\"waitForURL\", [serializedUrl, options?.timeout || null, options?.waitUntil || null], { pageId: this.#pageId });\n }\n async waitForRequest(urlOrPredicate, options) {\n if (typeof urlOrPredicate === 'function') {\n const userPredicate = urlOrPredicate;\n const wrappedPredicate = (data) => {\n const requestLike = {\n url: () => data.url,\n method: () => data.method,\n headers: () => Object.fromEntries(data.headers),\n headersArray: () => data.headers.map(h => ({ name: h[0], value: h[1] })),\n postData: () => data.body || null,\n };\n return userPredicate(requestLike);\n };\n const predicateId = __pw_register_predicate(wrappedPredicate);\n const pageId = this.#pageId;\n // Start listening immediately (before the user triggers the request)\n const broadMatcher = { type: 'regex', value: { $regex: '.*', $flags: '' } };\n const startResult = await __pw_invoke(\"waitForRequestStart\", [broadMatcher, options?.timeout || null], { pageId });\n const listenerId = startResult.listenerId;\n try {\n const r = await __pw_invoke(\"waitForRequestPredicateFinish\", [listenerId, predicateId, options?.timeout || null], { pageId });\n return { url: () => r.url, method: () => r.method, headers: () => r.headers, postData: () => r.postData };\n } finally {\n __pw_unregister_predicate(predicateId);\n }\n }\n let serializedMatcher;\n if (typeof urlOrPredicate === 'string') {\n serializedMatcher = { type: 'string', value: urlOrPredicate };\n } else if (urlOrPredicate && typeof urlOrPredicate === 'object'\n && typeof urlOrPredicate.source === 'string'\n && typeof urlOrPredicate.flags === 'string') {\n serializedMatcher = { type: 'regex', value: { $regex: urlOrPredicate.source, $flags: urlOrPredicate.flags } };\n } else {\n throw new Error('waitForRequest requires a URL string, RegExp, or predicate function');\n }\n const startResult = await __pw_invoke(\"waitForRequestStart\", [serializedMatcher, options?.timeout || null], { pageId: this.#pageId });\n const listenerId = startResult.listenerId;\n const pageId = this.#pageId;\n const r = await __pw_invoke(\"waitForRequestFinish\", [listenerId], { pageId });\n return { url: () => r.url, method: () => r.method, headers: () => r.headers, postData: () => r.postData };\n }\n async waitForResponse(urlOrPredicate, options) {\n if (typeof urlOrPredicate === 'function') {\n const userPredicate = urlOrPredicate;\n const wrappedPredicate = (data) => {\n const responseLike = {\n url: () => data.url,\n status: () => data.status,\n statusText: () => data.statusText,\n headers: () => Object.fromEntries(data.headers),\n headersArray: () => data.headers.map(h => ({ name: h[0], value: h[1] })),\n ok: () => data.status >= 200 && data.status < 300,\n };\n return userPredicate(responseLike);\n };\n const predicateId = __pw_register_predicate(wrappedPredicate);\n const pageId = this.#pageId;\n // Start listening immediately (before the user triggers the response)\n const broadMatcher = { type: 'regex', value: { $regex: '.*', $flags: '' } };\n const startResult = await __pw_invoke(\"waitForResponseStart\", [broadMatcher, options?.timeout || null], { pageId });\n const listenerId = startResult.listenerId;\n try {\n const r = await __pw_invoke(\"waitForResponsePredicateFinish\", [listenerId, predicateId, options?.timeout || null], { pageId });\n return {\n url: () => r.url, status: () => r.status, statusText: () => r.statusText,\n headers: () => r.headers, headersArray: () => r.headersArray,\n ok: () => r.ok, json: async () => r.json, text: async () => r.text, body: async () => r.body,\n };\n } finally {\n __pw_unregister_predicate(predicateId);\n }\n }\n let serializedMatcher;\n if (typeof urlOrPredicate === 'string') {\n serializedMatcher = { type: 'string', value: urlOrPredicate };\n } else if (urlOrPredicate && typeof urlOrPredicate === 'object'\n && typeof urlOrPredicate.source === 'string'\n && typeof urlOrPredicate.flags === 'string') {\n serializedMatcher = { type: 'regex', value: { $regex: urlOrPredicate.source, $flags: urlOrPredicate.flags } };\n } else {\n throw new Error('waitForResponse requires a URL string, RegExp, or predicate function');\n }\n const startResult = await __pw_invoke(\"waitForResponseStart\", [serializedMatcher, options?.timeout || null], { pageId: this.#pageId });\n const listenerId = startResult.listenerId;\n const pageId = this.#pageId;\n const r = await __pw_invoke(\"waitForResponseFinish\", [listenerId], { pageId });\n return {\n url: () => r.url, status: () => r.status, statusText: () => r.statusText,\n headers: () => r.headers, headersArray: () => r.headersArray,\n ok: () => r.ok, json: async () => r.json, text: async () => r.text, body: async () => r.body,\n };\n }\n context() {\n const contextId = this.#contextId;\n return new IsolateContext(contextId);\n }\n async click(selector) { return this.locator(selector).click(); }\n async fill(selector, value) { return this.locator(selector).fill(value); }\n async textContent(selector) { return this.locator(selector).textContent(); }\n async innerText(selector) { return this.locator(selector).innerText(); }\n async innerHTML(selector) { return this.locator(selector).innerHTML(); }\n async getAttribute(selector, name) { return this.locator(selector).getAttribute(name); }\n async inputValue(selector) { return this.locator(selector).inputValue(); }\n async isVisible(selector) { return this.locator(selector).isVisible(); }\n async isEnabled(selector) { return this.locator(selector).isEnabled(); }\n async isChecked(selector) { return this.locator(selector).isChecked(); }\n async isHidden(selector) { return this.locator(selector).isHidden(); }\n async isDisabled(selector) { return this.locator(selector).isDisabled(); }\n async screenshot(options) { return __pw_invoke(\"screenshot\", [options || {}], { pageId: this.#pageId }); }\n async setViewportSize(size) { return __pw_invoke(\"setViewportSize\", [size], { pageId: this.#pageId }); }\n async viewportSize() { return __pw_invoke(\"viewportSize\", [], { pageId: this.#pageId }); }\n async emulateMedia(options) { return __pw_invoke(\"emulateMedia\", [options], { pageId: this.#pageId }); }\n async setExtraHTTPHeaders(headers) { return __pw_invoke(\"setExtraHTTPHeaders\", [headers], { pageId: this.#pageId }); }\n async bringToFront() { return __pw_invoke(\"bringToFront\", [], { pageId: this.#pageId }); }\n async close() { return __pw_invoke(\"close\", [], { pageId: this.#pageId }); }\n async isClosed() { return __pw_invoke(\"isClosed\", [], { pageId: this.#pageId }); }\n async pdf(options) { return __pw_invoke(\"pdf\", [options || {}], { pageId: this.#pageId }); }\n async pause() { return __pw_invoke(\"pause\", [], { pageId: this.#pageId }); }\n async frames() { return __pw_invoke(\"frames\", [], { pageId: this.#pageId }); }\n async mainFrame() { return __pw_invoke(\"mainFrame\", [], { pageId: this.#pageId }); }\n get keyboard() {\n const pageId = this.#pageId;\n return {\n async type(text, options) { return __pw_invoke(\"keyboardType\", [text, options], { pageId }); },\n async press(key, options) { return __pw_invoke(\"keyboardPress\", [key, options], { pageId }); },\n async down(key) { return __pw_invoke(\"keyboardDown\", [key], { pageId }); },\n async up(key) { return __pw_invoke(\"keyboardUp\", [key], { pageId }); },\n async insertText(text) { return __pw_invoke(\"keyboardInsertText\", [text], { pageId }); }\n };\n }\n get mouse() {\n const pageId = this.#pageId;\n return {\n async move(x, y, options) { return __pw_invoke(\"mouseMove\", [x, y, options], { pageId }); },\n async click(x, y, options) { return __pw_invoke(\"mouseClick\", [x, y, options], { pageId }); },\n async down(options) { return __pw_invoke(\"mouseDown\", [options], { pageId }); },\n async up(options) { return __pw_invoke(\"mouseUp\", [options], { pageId }); },\n async wheel(deltaX, deltaY) { return __pw_invoke(\"mouseWheel\", [deltaX, deltaY], { pageId }); }\n };\n }\n get request() {\n const pageId = this.#pageId;\n return {\n async fetch(url, options) {\n const result = await __pw_invoke(\"request\", [url, options?.method || \"GET\", options?.data, options?.headers], { pageId });\n return {\n status: () => result.status,\n ok: () => result.ok,\n headers: () => result.headers,\n json: async () => result.json,\n text: async () => result.text,\n body: async () => result.body,\n };\n },\n async get(url, options) { return this.fetch(url, { ...options, method: \"GET\" }); },\n async post(url, options) { return this.fetch(url, { ...options, method: \"POST\" }); },\n async put(url, options) { return this.fetch(url, { ...options, method: \"PUT\" }); },\n async delete(url, options) { return this.fetch(url, { ...options, method: \"DELETE\" }); },\n };\n }\n }\n globalThis.IsolatePage = IsolatePage;\n\n // IsolateContext class - represents a browser context with a specific contextId\n class IsolateContext {\n #contextId;\n constructor(contextId) { this.#contextId = contextId; }\n get __contextId() { return this.#contextId; }\n\n async newPage() {\n const result = await __pw_invoke(\"newPage\", [], { contextId: this.#contextId });\n return new IsolatePage(result.pageId, this.#contextId);\n }\n async close() { return __pw_invoke(\"closeContext\", [], { contextId: this.#contextId }); }\n async clearCookies() { return __pw_invoke(\"clearCookies\", [], { contextId: this.#contextId }); }\n async addCookies(cookies) { return __pw_invoke(\"addCookies\", [cookies], { contextId: this.#contextId }); }\n async cookies(urls) { return __pw_invoke(\"cookies\", [urls], { contextId: this.#contextId }); }\n }\n globalThis.IsolateContext = IsolateContext;\n\n // browser global - for creating new contexts\n globalThis.browser = {\n async newContext(options) {\n const result = await __pw_invoke(\"newContext\", [options || null]);\n return new IsolateContext(result.contextId);\n }\n };\n\n // context global - represents the default context\n globalThis.context = new IsolateContext(\"ctx_0\");\n\n // page global - represents the default page\n globalThis.page = new IsolatePage(\"page_0\", \"ctx_0\");\n})();\n`);\n\n // Locator class with pageId support\n context.evalSync(`\n(function() {\n // Helper to serialize options including RegExp\n function serializeOptions(options) {\n if (!options) return null;\n const serialized = { ...options };\n if (options.name && typeof options.name === 'object' && typeof options.name.source === 'string' && typeof options.name.flags === 'string') {\n serialized.name = { $regex: options.name.source, $flags: options.name.flags };\n }\n return JSON.stringify(serialized);\n }\n\n const INPUT_FILES_VALIDATION_ERROR =\n \"setInputFiles() expects a file path string, an array of file path strings, \" +\n \"a single inline file object ({ name, mimeType, buffer }), or an array of inline file objects.\";\n\n function isInlineFileObject(value) {\n return !!value\n && typeof value === 'object'\n && typeof value.name === 'string'\n && typeof value.mimeType === 'string'\n && 'buffer' in value;\n }\n\n function encodeInlineFileBuffer(buffer) {\n if (typeof buffer === 'string') {\n return buffer;\n }\n let bytes;\n if (buffer instanceof ArrayBuffer) {\n bytes = new Uint8Array(buffer);\n } else if (ArrayBuffer.isView(buffer)) {\n bytes = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n } else {\n throw new Error(\n \"setInputFiles() inline file buffer must be a base64 string, ArrayBuffer, or TypedArray.\"\n );\n }\n let binary = '';\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i]);\n }\n return btoa(binary);\n }\n\n function serializeInlineFile(file) {\n return {\n name: file.name,\n mimeType: file.mimeType,\n buffer: encodeInlineFileBuffer(file.buffer),\n };\n }\n\n function normalizeSetInputFilesArg(files) {\n if (typeof files === 'string') {\n return files;\n }\n if (isInlineFileObject(files)) {\n return serializeInlineFile(files);\n }\n if (!Array.isArray(files)) {\n throw new Error(INPUT_FILES_VALIDATION_ERROR);\n }\n if (files.length === 0) {\n return [];\n }\n\n let hasPaths = false;\n let hasInline = false;\n const inlineFiles = [];\n\n for (const file of files) {\n if (typeof file === 'string') {\n hasPaths = true;\n continue;\n }\n if (isInlineFileObject(file)) {\n hasInline = true;\n inlineFiles.push(serializeInlineFile(file));\n continue;\n }\n throw new Error(INPUT_FILES_VALIDATION_ERROR);\n }\n\n if (hasPaths && hasInline) {\n throw new Error(\n \"setInputFiles() does not support mixing file paths and inline file objects in the same array.\"\n );\n }\n return hasInline ? inlineFiles : files;\n }\n\n class Locator {\n #type; #value; #options; #pageId;\n constructor(type, value, options, pageId) {\n this.#type = type;\n this.#value = value;\n this.#options = options;\n this.#pageId = pageId || \"page_0\";\n }\n\n _getInfo() { return [this.#type, this.#value, this.#options]; }\n _getPageId() { return this.#pageId; }\n\n // Helper to create a chained locator\n _chain(childType, childValue, childOptions) {\n const parentInfo = this._getInfo();\n const childInfo = [childType, childValue, childOptions];\n return new Locator(\"chained\", JSON.stringify([parentInfo, childInfo]), null, this.#pageId);\n }\n\n async click() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"click\", null], { pageId: this.#pageId });\n }\n async dblclick() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"dblclick\", null], { pageId: this.#pageId });\n }\n async fill(text) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"fill\", text], { pageId: this.#pageId });\n }\n async type(text) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"type\", text], { pageId: this.#pageId });\n }\n async check() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"check\", null], { pageId: this.#pageId });\n }\n async uncheck() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"uncheck\", null], { pageId: this.#pageId });\n }\n async selectOption(value) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"selectOption\", value], { pageId: this.#pageId });\n }\n async clear() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"clear\", null], { pageId: this.#pageId });\n }\n async press(key) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"press\", key], { pageId: this.#pageId });\n }\n async hover() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"hover\", null], { pageId: this.#pageId });\n }\n async focus() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"focus\", null], { pageId: this.#pageId });\n }\n async textContent() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"getText\", null], { pageId: this.#pageId });\n }\n async inputValue() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"getValue\", null], { pageId: this.#pageId });\n }\n async isVisible() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isVisible\", null], { pageId: this.#pageId });\n }\n async isEnabled() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isEnabled\", null], { pageId: this.#pageId });\n }\n async isChecked() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isChecked\", null], { pageId: this.#pageId });\n }\n async count() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"count\", null], { pageId: this.#pageId });\n }\n async getAttribute(name) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"getAttribute\", name], { pageId: this.#pageId });\n }\n async isDisabled() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isDisabled\", null], { pageId: this.#pageId });\n }\n async isHidden() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"isHidden\", null], { pageId: this.#pageId });\n }\n async innerHTML() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"innerHTML\", null], { pageId: this.#pageId });\n }\n async innerText() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"innerText\", null], { pageId: this.#pageId });\n }\n async allTextContents() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"allTextContents\", null], { pageId: this.#pageId });\n }\n async allInnerTexts() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"allInnerTexts\", null], { pageId: this.#pageId });\n }\n async waitFor(options) {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"waitFor\", options || {}], { pageId: this.#pageId });\n }\n async boundingBox() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"boundingBox\", null], { pageId: this.#pageId });\n }\n async setInputFiles(files) {\n const serializedFiles = normalizeSetInputFilesArg(files);\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"setInputFiles\", serializedFiles], { pageId: this.#pageId });\n }\n async screenshot(options) {\n const base64 = await __pw_invoke(\"locatorAction\", [...this._getInfo(), \"screenshot\", options || {}], { pageId: this.#pageId });\n return base64;\n }\n async dragTo(target) {\n const targetInfo = target._getInfo();\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"dragTo\", targetInfo], { pageId: this.#pageId });\n }\n async scrollIntoViewIfNeeded() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"scrollIntoViewIfNeeded\", null], { pageId: this.#pageId });\n }\n async highlight() {\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"highlight\", null], { pageId: this.#pageId });\n }\n async evaluate(fn, arg) {\n const fnString = typeof fn === 'function' ? fn.toString() : fn;\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"evaluate\", [fnString, arg]], { pageId: this.#pageId });\n }\n async evaluateAll(fn, arg) {\n const fnString = typeof fn === 'function' ? fn.toString() : fn;\n return __pw_invoke(\"locatorAction\", [...this._getInfo(), \"evaluateAll\", [fnString, arg]], { pageId: this.#pageId });\n }\n locator(selector) {\n return this._chain(\"css\", selector, null);\n }\n // Chaining: getBy* methods within a locator\n getByRole(role, options) {\n return this._chain(\"role\", role, serializeOptions(options));\n }\n getByText(text) {\n return this._chain(\"text\", text, null);\n }\n getByLabel(label) {\n return this._chain(\"label\", label, null);\n }\n getByPlaceholder(placeholder) {\n return this._chain(\"placeholder\", placeholder, null);\n }\n getByTestId(testId) {\n return this._chain(\"testId\", testId, null);\n }\n getByAltText(altText) {\n return this._chain(\"altText\", altText, null);\n }\n getByTitle(title) {\n return this._chain(\"title\", title, null);\n }\n async all() {\n const n = await this.count();\n const result = [];\n for (let i = 0; i < n; i++) {\n result.push(this.nth(i));\n }\n return result;\n }\n nth(index) {\n const existingOpts = this.#options ? JSON.parse(this.#options) : {};\n return new Locator(this.#type, this.#value, JSON.stringify({ ...existingOpts, nth: index }), this.#pageId);\n }\n first() {\n return this.nth(0);\n }\n last() {\n return this.nth(-1);\n }\n filter(options) {\n const existingOpts = this.#options ? JSON.parse(this.#options) : {};\n const serializedFilter = { ...options };\n // Use duck-typing RegExp detection (instanceof fails across isolated-vm boundary)\n const hasText = options.hasText;\n if (hasText && typeof hasText === 'object' && typeof hasText.source === 'string' && typeof hasText.flags === 'string') {\n serializedFilter.hasText = { $regex: hasText.source, $flags: hasText.flags };\n }\n const hasNotText = options.hasNotText;\n if (hasNotText && typeof hasNotText === 'object' && typeof hasNotText.source === 'string' && typeof hasNotText.flags === 'string') {\n serializedFilter.hasNotText = { $regex: hasNotText.source, $flags: hasNotText.flags };\n }\n // Serialize has/hasNot locators using duck-typing\n const has = options.has;\n if (has && typeof has === 'object' && typeof has._getInfo === 'function') {\n serializedFilter.has = { $locator: has._getInfo() };\n }\n const hasNot = options.hasNot;\n if (hasNot && typeof hasNot === 'object' && typeof hasNot._getInfo === 'function') {\n serializedFilter.hasNot = { $locator: hasNot._getInfo() };\n }\n return new Locator(this.#type, this.#value, JSON.stringify({ ...existingOpts, filter: serializedFilter }), this.#pageId);\n }\n or(other) {\n // Create a composite locator that matches either this or other\n const thisInfo = this._getInfo();\n const otherInfo = other._getInfo();\n return new Locator(\"or\", JSON.stringify([thisInfo, otherInfo]), null, this.#pageId);\n }\n and(other) {\n // Create a composite locator that matches both this and other\n const thisInfo = this._getInfo();\n const otherInfo = other._getInfo();\n return new Locator(\"and\", JSON.stringify([thisInfo, otherInfo]), null, this.#pageId);\n }\n }\n globalThis.Locator = Locator;\n})();\n`);\n\n // Extend expect with locator matchers (only if test-environment already defined expect)\n context.evalSync(`\n(function() {\n // Helper to create locator matchers\n function createLocatorMatchers(locator, baseMatchers) {\n const info = locator._getInfo();\n const pageId = locator._getPageId ? locator._getPageId() : \"page_0\";\n\n // Helper for serializing regex values\n function serializeExpected(expected) {\n if (expected instanceof RegExp) {\n return { $regex: expected.source, $flags: expected.flags };\n }\n return expected;\n }\n\n const locatorMatchers = {\n async toBeVisible(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeVisible\", null, false, options?.timeout], { pageId });\n },\n async toContainText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainText\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveValue(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveValue\", expected, false, options?.timeout], { pageId });\n },\n async toBeEnabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEnabled\", null, false, options?.timeout], { pageId });\n },\n async toBeChecked(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeChecked\", null, false, options?.timeout], { pageId });\n },\n async toHaveAttribute(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAttribute\", { name, value: serializeExpected(value) }, false, options?.timeout], { pageId });\n },\n async toHaveText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveText\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveCount(count, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCount\", count, false, options?.timeout], { pageId });\n },\n async toBeHidden(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeHidden\", null, false, options?.timeout], { pageId });\n },\n async toBeDisabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeDisabled\", null, false, options?.timeout], { pageId });\n },\n async toBeFocused(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeFocused\", null, false, options?.timeout], { pageId });\n },\n async toBeEmpty(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEmpty\", null, false, options?.timeout], { pageId });\n },\n // New matchers\n async toBeAttached(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeAttached\", null, false, options?.timeout], { pageId });\n },\n async toBeEditable(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEditable\", null, false, options?.timeout], { pageId });\n },\n async toHaveClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveClass\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toContainClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainClass\", expected, false, options?.timeout], { pageId });\n },\n async toHaveId(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveId\", expected, false, options?.timeout], { pageId });\n },\n async toBeInViewport(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeInViewport\", null, false, options?.timeout], { pageId });\n },\n async toHaveCSS(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCSS\", { name, value: serializeExpected(value) }, false, options?.timeout], { pageId });\n },\n async toHaveJSProperty(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveJSProperty\", { name, value }, false, options?.timeout], { pageId });\n },\n async toHaveAccessibleName(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleName\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveAccessibleDescription(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleDescription\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveRole(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveRole\", expected, false, options?.timeout], { pageId });\n },\n not: {\n async toBeVisible(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeVisible\", null, true, options?.timeout], { pageId });\n },\n async toContainText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainText\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveValue(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveValue\", expected, true, options?.timeout], { pageId });\n },\n async toBeEnabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEnabled\", null, true, options?.timeout], { pageId });\n },\n async toBeChecked(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeChecked\", null, true, options?.timeout], { pageId });\n },\n async toHaveAttribute(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAttribute\", { name, value: serializeExpected(value) }, true, options?.timeout], { pageId });\n },\n async toHaveText(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveText\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveCount(count, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCount\", count, true, options?.timeout], { pageId });\n },\n async toBeHidden(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeHidden\", null, true, options?.timeout], { pageId });\n },\n async toBeDisabled(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeDisabled\", null, true, options?.timeout], { pageId });\n },\n async toBeFocused(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeFocused\", null, true, options?.timeout], { pageId });\n },\n async toBeEmpty(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEmpty\", null, true, options?.timeout], { pageId });\n },\n // New negated matchers\n async toBeAttached(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeAttached\", null, true, options?.timeout], { pageId });\n },\n async toBeEditable(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeEditable\", null, true, options?.timeout], { pageId });\n },\n async toHaveClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveClass\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toContainClass(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toContainClass\", expected, true, options?.timeout], { pageId });\n },\n async toHaveId(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveId\", expected, true, options?.timeout], { pageId });\n },\n async toBeInViewport(options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toBeInViewport\", null, true, options?.timeout], { pageId });\n },\n async toHaveCSS(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveCSS\", { name, value: serializeExpected(value) }, true, options?.timeout], { pageId });\n },\n async toHaveJSProperty(name, value, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveJSProperty\", { name, value }, true, options?.timeout], { pageId });\n },\n async toHaveAccessibleName(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleName\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveAccessibleDescription(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveAccessibleDescription\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveRole(expected, options) {\n return __pw_invoke(\"expectLocator\", [...info, \"toHaveRole\", expected, true, options?.timeout], { pageId });\n },\n }\n };\n\n // Merge locator matchers with base matchers from test-environment\n if (baseMatchers) {\n return {\n ...baseMatchers,\n ...locatorMatchers,\n not: { ...baseMatchers.not, ...locatorMatchers.not }\n };\n }\n return locatorMatchers;\n }\n\n // Helper to create page matchers\n function createPageMatchers(page, baseMatchers) {\n const pageId = page.__pageId || \"page_0\";\n\n function serializeExpected(expected) {\n if (expected instanceof RegExp) {\n return { $regex: expected.source, $flags: expected.flags };\n }\n return expected;\n }\n\n const pageMatchers = {\n async toHaveURL(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveURL\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n async toHaveTitle(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveTitle\", serializeExpected(expected), false, options?.timeout], { pageId });\n },\n not: {\n async toHaveURL(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveURL\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n async toHaveTitle(expected, options) {\n return __pw_invoke(\"expectPage\", [\"toHaveTitle\", serializeExpected(expected), true, options?.timeout], { pageId });\n },\n }\n };\n\n if (baseMatchers) {\n return {\n ...baseMatchers,\n ...pageMatchers,\n not: { ...baseMatchers.not, ...pageMatchers.not }\n };\n }\n return pageMatchers;\n }\n\n // Only extend expect if test-environment already defined it\n if (typeof globalThis.expect === 'function') {\n const originalExpect = globalThis.expect;\n globalThis.expect = function(actual) {\n const baseMatchers = originalExpect(actual);\n // If actual is a Locator, add locator-specific matchers\n if (actual && actual.constructor && actual.constructor.name === 'Locator') {\n return createLocatorMatchers(actual, baseMatchers);\n }\n // If actual is the page object (IsolatePage), add page-specific matchers\n if (actual && actual.__isPage === true) {\n return createPageMatchers(actual, baseMatchers);\n }\n return baseMatchers;\n };\n }\n // If test-environment not loaded, expect remains undefined\n})();\n`);\n\n // ========================================================================\n // Return Handle\n // ========================================================================\n\n return {\n dispose() {\n // Only remove listeners if page was provided directly\n if (page && requestHandler && responseHandler && requestFailedHandler && consoleHandler && pageErrorHandler) {\n page.off(\"request\", requestHandler);\n page.off(\"response\", responseHandler);\n page.off(\"requestfailed\", requestFailedHandler);\n page.off(\"console\", consoleHandler);\n page.off(\"pageerror\", pageErrorHandler);\n }\n browserConsoleLogs.length = 0;\n pageErrors.length = 0;\n networkRequests.length = 0;\n networkResponses.length = 0;\n requestFailures.length = 0;\n },\n getBrowserConsoleLogs() {\n return [...browserConsoleLogs];\n },\n getPageErrors() {\n return [...pageErrors];\n },\n getNetworkRequests() {\n return [...networkRequests];\n },\n getNetworkResponses() {\n return [...networkResponses];\n },\n getRequestFailures() {\n return [...requestFailures];\n },\n clearCollected() {\n browserConsoleLogs.length = 0;\n pageErrors.length = 0;\n networkRequests.length = 0;\n networkResponses.length = 0;\n requestFailures.length = 0;\n },\n };\n}\n"
|
|
6
6
|
],
|
|
7
7
|
"mappings": ";AAAA;AAIA;AAAA;AAAA;AAKA;AAAA;AAAA;AAAA;AAAA;AAuBA;AAAA,6BACE;AAAA,yCACA;AAAA;AAsBF,SAAS,+BAA+B,CACtC,SACA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,cAAc;AAAA,QAClC,KAAK,IAAI,YAAY,eAAe;AAAA,QACpC,KAAK,IAAI,iBAAiB,oBAAoB;AAAA,QAC9C,KAAK,IAAI,WAAW,cAAc;AAAA,QAClC,KAAK,IAAI,aAAa,gBAAgB;AAAA,MACxC;AAAA,MACA,mBAAmB,SAAS;AAAA,MAC5B,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,MACzB,iBAAiB,SAAS;AAAA,MAC1B,gBAAgB,SAAS;AAAA;AAAA,IAE3B,qBAAqB,GAAG;AAAA,MACtB,OAAO,CAAC,GAAG,kBAAkB;AAAA;AAAA,IAE/B,aAAa,GAAG;AAAA,MACd,OAAO,CAAC,GAAG,UAAU;AAAA;AAAA,IAEvB,kBAAkB,GAAG;AAAA,MACnB,OAAO,CAAC,GAAG,eAAe;AAAA;AAAA,IAE5B,mBAAmB,GAAG;AAAA,MACpB,OAAO,CAAC,GAAG,gBAAgB;AAAA;AAAA,IAE7B,kBAAkB,GAAG;AAAA,MACnB,OAAO,CAAC,GAAG,eAAe;AAAA;AAAA,IAE5B,cAAc,GAAG;AAAA,MACf,mBAAmB,SAAS;AAAA,MAC5B,WAAW,SAAS;AAAA,MACpB,gBAAgB,SAAS;AAAA,MACzB,iBAAiB,SAAS;AAAA,MAC1B,gBAAgB,SAAS;AAAA;AAAA,EAE7B;AAAA;",
|
|
8
|
-
"debugId": "
|
|
8
|
+
"debugId": "D072F79E375B765364756E2164756E21",
|
|
9
9
|
"names": []
|
|
10
10
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/internal/runtime/index.ts
|
|
2
|
-
import ivm from "isolated-vm";
|
|
2
|
+
import ivm from "@ricsam/isolated-vm";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { setupCore } from "../core/index.mjs";
|
|
5
|
+
import { setupAsyncContext } from "../async-context/index.mjs";
|
|
5
6
|
import { normalizeEntryFilename } from "../protocol/index.mjs";
|
|
6
7
|
import {
|
|
7
8
|
transformEntryCode,
|
|
@@ -166,6 +167,20 @@ async function runWithExecutionTimeout(state, timeoutMs, label, operation) {
|
|
|
166
167
|
var iteratorSessions = new Map;
|
|
167
168
|
var ISOLATE_MARSHAL_CODE = `
|
|
168
169
|
(function() {
|
|
170
|
+
const __wrapAsyncContextCallback = (callback) => (
|
|
171
|
+
typeof callback === 'function' && globalThis.__isolateAsyncContextInternals?.wrapCallback
|
|
172
|
+
? globalThis.__isolateAsyncContextInternals.wrapCallback(callback, { type: 'isolate.callback' })
|
|
173
|
+
: callback
|
|
174
|
+
);
|
|
175
|
+
let __customFn_nextCallbackId = 1;
|
|
176
|
+
const __customFn_callbacks = new Map();
|
|
177
|
+
|
|
178
|
+
function __customFn_registerCallback(callback) {
|
|
179
|
+
const callbackId = __customFn_nextCallbackId++;
|
|
180
|
+
__customFn_callbacks.set(callbackId, __wrapAsyncContextCallback(callback));
|
|
181
|
+
return callbackId;
|
|
182
|
+
}
|
|
183
|
+
|
|
169
184
|
// Marshal a value (JavaScript → Ref)
|
|
170
185
|
function marshalForHost(value, depth = 0) {
|
|
171
186
|
if (depth > 100) throw new Error('Maximum marshalling depth exceeded');
|
|
@@ -176,7 +191,9 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
176
191
|
const type = typeof value;
|
|
177
192
|
if (type === 'string' || type === 'number' || type === 'boolean') return value;
|
|
178
193
|
if (type === 'bigint') return { __type: 'BigIntRef', value: value.toString() };
|
|
179
|
-
if (type === 'function')
|
|
194
|
+
if (type === 'function') {
|
|
195
|
+
return { __type: 'CallbackRef', callbackId: __customFn_registerCallback(value) };
|
|
196
|
+
}
|
|
180
197
|
if (type === 'symbol') throw new Error('Cannot marshal Symbol values');
|
|
181
198
|
|
|
182
199
|
if (type === 'object') {
|
|
@@ -228,6 +245,35 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
228
245
|
return value;
|
|
229
246
|
}
|
|
230
247
|
|
|
248
|
+
async function invokeLocalCallback(callbackId, argsJson) {
|
|
249
|
+
const callback = __customFn_callbacks.get(callbackId);
|
|
250
|
+
if (!callback) {
|
|
251
|
+
return JSON.stringify({
|
|
252
|
+
ok: false,
|
|
253
|
+
error: {
|
|
254
|
+
message: 'Callback ' + callbackId + ' not found',
|
|
255
|
+
name: 'Error',
|
|
256
|
+
},
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
try {
|
|
261
|
+
const rawArgs = JSON.parse(argsJson);
|
|
262
|
+
const args = unmarshalFromHost(rawArgs);
|
|
263
|
+
const result = await callback(...args);
|
|
264
|
+
return JSON.stringify({ ok: true, value: marshalForHost(result) });
|
|
265
|
+
} catch (error) {
|
|
266
|
+
const err = error instanceof Error ? error : new Error(String(error));
|
|
267
|
+
return JSON.stringify({
|
|
268
|
+
ok: false,
|
|
269
|
+
error: {
|
|
270
|
+
message: err.message,
|
|
271
|
+
name: err.name,
|
|
272
|
+
},
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
231
277
|
// Unmarshal a value (Ref → JavaScript)
|
|
232
278
|
function unmarshalFromHost(value, depth = 0) {
|
|
233
279
|
if (depth > 100) throw new Error('Maximum unmarshalling depth exceeded');
|
|
@@ -415,14 +461,16 @@ var ISOLATE_MARSHAL_CODE = `
|
|
|
415
461
|
// Expose as globals
|
|
416
462
|
globalThis.__marshalForHost = marshalForHost;
|
|
417
463
|
globalThis.__unmarshalFromHost = unmarshalFromHost;
|
|
464
|
+
globalThis.__customFn_invokeLocalCallback = invokeLocalCallback;
|
|
418
465
|
})();
|
|
419
466
|
`;
|
|
420
467
|
async function setupCustomFunctions(context, customFunctions, marshalOptions) {
|
|
421
468
|
const global = context.global;
|
|
469
|
+
const isolateUnmarshalContext = {};
|
|
422
470
|
const invokeCallbackRef = new ivm.Reference(async (nameOrId, argsJson) => {
|
|
423
471
|
if (typeof nameOrId === "number" && marshalOptions) {
|
|
424
472
|
const rawArgs2 = JSON.parse(argsJson);
|
|
425
|
-
const args2 = unmarshalValue(rawArgs2);
|
|
473
|
+
const args2 = unmarshalValue(rawArgs2, isolateUnmarshalContext);
|
|
426
474
|
try {
|
|
427
475
|
const result = await marshalOptions.invokeCallback(nameOrId, args2);
|
|
428
476
|
const ctx = marshalOptions.createMarshalContext();
|
|
@@ -449,7 +497,7 @@ async function setupCustomFunctions(context, customFunctions, marshalOptions) {
|
|
|
449
497
|
});
|
|
450
498
|
}
|
|
451
499
|
const rawArgs = JSON.parse(argsJson);
|
|
452
|
-
const args = unmarshalValue(rawArgs);
|
|
500
|
+
const args = unmarshalValue(rawArgs, isolateUnmarshalContext);
|
|
453
501
|
try {
|
|
454
502
|
const result = await def.fn(...args);
|
|
455
503
|
if (marshalOptions) {
|
|
@@ -470,6 +518,27 @@ async function setupCustomFunctions(context, customFunctions, marshalOptions) {
|
|
|
470
518
|
});
|
|
471
519
|
global.setSync("__customFn_invoke", invokeCallbackRef);
|
|
472
520
|
context.evalSync(ISOLATE_MARSHAL_CODE);
|
|
521
|
+
const invokeIsolateCallbackRef = context.global.getSync("__customFn_invokeLocalCallback", { reference: true });
|
|
522
|
+
isolateUnmarshalContext.getCallback = (callbackId) => {
|
|
523
|
+
return async (...args) => {
|
|
524
|
+
let marshalledArgs;
|
|
525
|
+
if (marshalOptions) {
|
|
526
|
+
const ctx = marshalOptions.createMarshalContext();
|
|
527
|
+
marshalledArgs = await marshalValue(args, ctx);
|
|
528
|
+
marshalledArgs = marshalOptions.addCallbackIdsToRefs(marshalledArgs);
|
|
529
|
+
} else {
|
|
530
|
+
marshalledArgs = await marshalValue(args);
|
|
531
|
+
}
|
|
532
|
+
const resultJson = await invokeIsolateCallbackRef.apply(undefined, [callbackId, JSON.stringify(marshalledArgs)], { result: { promise: true, copy: true } });
|
|
533
|
+
const result = JSON.parse(resultJson);
|
|
534
|
+
if (result.ok) {
|
|
535
|
+
return unmarshalValue(result.value, isolateUnmarshalContext);
|
|
536
|
+
}
|
|
537
|
+
const error = new Error(result.error?.message ?? `Callback ${callbackId} failed`);
|
|
538
|
+
error.name = result.error?.name ?? "Error";
|
|
539
|
+
throw error;
|
|
540
|
+
};
|
|
541
|
+
};
|
|
473
542
|
for (const name of Object.keys(customFunctions)) {
|
|
474
543
|
const def = customFunctions[name];
|
|
475
544
|
if (def.type === "async") {
|
|
@@ -796,7 +865,9 @@ async function createRuntime(options) {
|
|
|
796
865
|
const isolate = new ivm.Isolate({
|
|
797
866
|
memoryLimit: opts.memoryLimitMB
|
|
798
867
|
});
|
|
799
|
-
const context = await isolate.createContext(
|
|
868
|
+
const context = await isolate.createContext({
|
|
869
|
+
asyncContext: true
|
|
870
|
+
});
|
|
800
871
|
const state = {
|
|
801
872
|
id,
|
|
802
873
|
isolate,
|
|
@@ -817,6 +888,7 @@ async function createRuntime(options) {
|
|
|
817
888
|
moduleLoader: opts.moduleLoader,
|
|
818
889
|
customFunctions: opts.customFunctions
|
|
819
890
|
};
|
|
891
|
+
await setupAsyncContext(context);
|
|
820
892
|
state.handles.core = await setupCore(context);
|
|
821
893
|
state.handles.console = await setupConsole(context, opts.console);
|
|
822
894
|
state.handles.encoding = await setupEncoding(context);
|
|
@@ -1195,4 +1267,4 @@ export {
|
|
|
1195
1267
|
createNodeFileSystemHandler
|
|
1196
1268
|
};
|
|
1197
1269
|
|
|
1198
|
-
//# debugId=
|
|
1270
|
+
//# debugId=46DA9086D0B9D52764756E2164756E21
|