@pedropaulovc/playwright-core 1.59.0-next → 1.59.0-next.3

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.
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -39,7 +39,7 @@ var import_driver = require("./driver");
39
39
  var import_server = require("../server");
40
40
  var import_utils = require("../utils");
41
41
  var import_traceViewer = require("../server/trace/viewer/traceViewer");
42
- var import_traceExporter = require("../server/trace/viewer/traceExporter");
42
+ var import_src = require("../../../../trace-exporter/src");
43
43
  var import_utils2 = require("../utils");
44
44
  var import_ascii = require("../server/utils/ascii");
45
45
  var import_utilsBundle = require("../utilsBundle");
@@ -295,19 +295,17 @@ Examples:
295
295
 
296
296
  $ show-trace
297
297
  $ show-trace https://example.com/trace.zip`);
298
- import_utilsBundle.program.command("export-trace <trace>").description("export trace to LLM-friendly markdown files").option("-o, --output <dir>", "output directory", "./trace-export").option("--no-assets", "skip extracting screenshots and snapshots").action(async function(trace, options) {
298
+ import_utilsBundle.program.command("export-trace <trace>").description("export trace to LLM-friendly markdown files").option("-o, --output <dir>", "output directory", "./trace-export").action(async function(trace, options) {
299
299
  const traceFile = import_path.default.resolve(trace);
300
- await (0, import_traceExporter.exportTraceToMarkdown)(traceFile, {
301
- outputDir: import_path.default.resolve(options.output),
302
- includeAssets: options.assets
300
+ await (0, import_src.exportTraceToMarkdown)(traceFile, {
301
+ outputDir: import_path.default.resolve(options.output)
303
302
  }).catch(logErrorAndExit);
304
303
  console.log(`Trace exported to ${options.output}`);
305
304
  }).addHelpText("afterAll", `
306
305
  Examples:
307
306
 
308
307
  $ export-trace trace.zip
309
- $ export-trace trace.zip -o ./my-export
310
- $ export-trace trace.zip --no-assets`);
308
+ $ export-trace trace.zip -o ./my-export`);
311
309
  async function launchContext(options, extraOptions) {
312
310
  validateOptions(options);
313
311
  const browserType = lookupBrowserType(options);
@@ -676,7 +676,6 @@ class Page extends import_channelOwner.ChannelOwner {
676
676
  }
677
677
  return result.pdf;
678
678
  }
679
- // @ts-expect-error agents are hidden
680
679
  async agent(options = {}) {
681
680
  const params = {
682
681
  api: options.provider?.api,
@@ -691,7 +690,6 @@ class Page extends import_channelOwner.ChannelOwner {
691
690
  maxTokens: options.limits?.maxTokens,
692
691
  maxActions: options.limits?.maxActions,
693
692
  maxActionRetries: options.limits?.maxActionRetries,
694
- // @ts-expect-error runAgents is hidden
695
693
  secrets: options.secrets ? Object.entries(options.secrets).map(([name, value]) => ({ name, value })) : void 0,
696
694
  systemPrompt: options.systemPrompt
697
695
  };
@@ -63,6 +63,9 @@ const wsServer = require("./utilsBundleImpl").wsServer;
63
63
  const wsReceiver = require("./utilsBundleImpl").wsReceiver;
64
64
  const wsSender = require("./utilsBundleImpl").wsSender;
65
65
  const yaml = require("./utilsBundleImpl").yaml;
66
+ program.exitOverride((err) => {
67
+ process.stdout.write("", () => process.stderr.write("", () => process.exit(err.exitCode)));
68
+ });
66
69
  function ms(ms2) {
67
70
  if (!isFinite(ms2))
68
71
  return "-";
File without changes
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@pedropaulovc/playwright-core",
3
- "version": "1.59.0-next",
3
+ "version": "1.59.0-next.3",
4
4
  "description": "A high-level API to automate web browsers",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/microsoft/playwright.git"
7
+ "url": "git+https://github.com/pedropaulovc/playwright.git"
8
8
  },
9
9
  "homepage": "https://playwright.dev",
10
10
  "engines": {
package/types/types.d.ts CHANGED
@@ -27,6 +27,13 @@ type ElementHandleWaitForSelectorOptionsNotHidden = ElementHandleWaitForSelector
27
27
  state?: 'visible'|'attached';
28
28
  };
29
29
 
30
+ // @ts-ignore this will be any if zod is not installed
31
+ import { ZodTypeAny, z } from 'zod';
32
+ // @ts-ignore this will be any if zod is not installed
33
+ import * as z3 from 'zod/v3';
34
+ type ZodSchema = ZodTypeAny | z3.ZodTypeAny;
35
+ type InferZodSchema<T extends ZodSchema> = T extends z3.ZodTypeAny ? z3.infer<T> : T extends ZodTypeAny ? z.infer<T> : never;
36
+
30
37
  /**
31
38
  * Page provides methods to interact with a single tab in a [Browser](https://playwright.dev/docs/api/class-browser),
32
39
  * or an [extension background page](https://developer.chrome.com/extensions/background_pages) in Chromium. One
@@ -2088,6 +2095,89 @@ export interface Page {
2088
2095
  url?: string;
2089
2096
  }): Promise<ElementHandle>;
2090
2097
 
2098
+ /**
2099
+ * Initialize page agent with the llm provider and cache.
2100
+ * @param options
2101
+ */
2102
+ agent(options?: {
2103
+ cache?: {
2104
+ /**
2105
+ * Cache file to use/generate code for performed actions into. Cache is not used if not specified (default).
2106
+ */
2107
+ cacheFile?: string;
2108
+
2109
+ /**
2110
+ * When specified, generated entries are written into the `cacheOutFile` instead of updating the `cacheFile`.
2111
+ */
2112
+ cacheOutFile?: string;
2113
+ };
2114
+
2115
+ expect?: {
2116
+ /**
2117
+ * Default timeout for expect calls in milliseconds, defaults to 5000ms.
2118
+ */
2119
+ timeout?: number;
2120
+ };
2121
+
2122
+ /**
2123
+ * Limits to use for the agentic loop.
2124
+ */
2125
+ limits?: {
2126
+ /**
2127
+ * Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value.
2128
+ * Defaults to unlimited.
2129
+ */
2130
+ maxTokens?: number;
2131
+
2132
+ /**
2133
+ * Maximum number of agentic actions to generate, defaults to 10.
2134
+ */
2135
+ maxActions?: number;
2136
+
2137
+ /**
2138
+ * Maximum number retries per action, defaults to 3.
2139
+ */
2140
+ maxActionRetries?: number;
2141
+ };
2142
+
2143
+ provider?: {
2144
+ /**
2145
+ * API to use.
2146
+ */
2147
+ api: "openai"|"openai-compatible"|"anthropic"|"google";
2148
+
2149
+ /**
2150
+ * Endpoint to use if different from default.
2151
+ */
2152
+ apiEndpoint?: string;
2153
+
2154
+ /**
2155
+ * API key for the LLM provider.
2156
+ */
2157
+ apiKey: string;
2158
+
2159
+ /**
2160
+ * Amount of time to wait for the provider to respond to each request.
2161
+ */
2162
+ apiTimeout?: number;
2163
+
2164
+ /**
2165
+ * Model identifier within the provider. Required in non-cache mode.
2166
+ */
2167
+ model: string;
2168
+ };
2169
+
2170
+ /**
2171
+ * Secrets to hide from the LLM.
2172
+ */
2173
+ secrets?: { [key: string]: string; };
2174
+
2175
+ /**
2176
+ * System prompt for the agent's loop.
2177
+ */
2178
+ systemPrompt?: string;
2179
+ }): Promise<PageAgent>;
2180
+
2091
2181
  /**
2092
2182
  * Brings page to front (activates tab).
2093
2183
  */
@@ -5204,6 +5294,243 @@ export interface Page {
5204
5294
  [Symbol.asyncDispose](): Promise<void>;
5205
5295
  }
5206
5296
 
5297
+ /**
5298
+ *
5299
+ */
5300
+ export interface PageAgent {
5301
+ /**
5302
+ * Extract information from the page using the agentic loop, return it in a given Zod format.
5303
+ *
5304
+ * **Usage**
5305
+ *
5306
+ * ```js
5307
+ * await agent.extract('List of items in the cart', z.object({
5308
+ * title: z.string().describe('Item title to extract'),
5309
+ * price: z.string().describe('Item price to extract'),
5310
+ * }).array());
5311
+ * ```
5312
+ *
5313
+ * @param query Task to perform using agentic loop.
5314
+ * @param schema
5315
+ * @param options
5316
+ */
5317
+ extract<Schema extends ZodSchema>(query: string, schema: Schema): Promise<{ result: InferZodSchema<Schema>, usage: { turns: number, inputTokens: number, outputTokens: number } }>;
5318
+ /**
5319
+ * Emitted when the agent makes a turn.
5320
+ */
5321
+ on(event: 'turn', listener: (data: {
5322
+ role: string;
5323
+
5324
+ message: string;
5325
+
5326
+ usage?: {
5327
+ inputTokens: number;
5328
+
5329
+ outputTokens: number;
5330
+ };
5331
+ }) => any): this;
5332
+
5333
+ /**
5334
+ * Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.
5335
+ */
5336
+ once(event: 'turn', listener: (data: {
5337
+ role: string;
5338
+
5339
+ message: string;
5340
+
5341
+ usage?: {
5342
+ inputTokens: number;
5343
+
5344
+ outputTokens: number;
5345
+ };
5346
+ }) => any): this;
5347
+
5348
+ /**
5349
+ * Emitted when the agent makes a turn.
5350
+ */
5351
+ addListener(event: 'turn', listener: (data: {
5352
+ role: string;
5353
+
5354
+ message: string;
5355
+
5356
+ usage?: {
5357
+ inputTokens: number;
5358
+
5359
+ outputTokens: number;
5360
+ };
5361
+ }) => any): this;
5362
+
5363
+ /**
5364
+ * Removes an event listener added by `on` or `addListener`.
5365
+ */
5366
+ removeListener(event: 'turn', listener: (data: {
5367
+ role: string;
5368
+
5369
+ message: string;
5370
+
5371
+ usage?: {
5372
+ inputTokens: number;
5373
+
5374
+ outputTokens: number;
5375
+ };
5376
+ }) => any): this;
5377
+
5378
+ /**
5379
+ * Removes an event listener added by `on` or `addListener`.
5380
+ */
5381
+ off(event: 'turn', listener: (data: {
5382
+ role: string;
5383
+
5384
+ message: string;
5385
+
5386
+ usage?: {
5387
+ inputTokens: number;
5388
+
5389
+ outputTokens: number;
5390
+ };
5391
+ }) => any): this;
5392
+
5393
+ /**
5394
+ * Emitted when the agent makes a turn.
5395
+ */
5396
+ prependListener(event: 'turn', listener: (data: {
5397
+ role: string;
5398
+
5399
+ message: string;
5400
+
5401
+ usage?: {
5402
+ inputTokens: number;
5403
+
5404
+ outputTokens: number;
5405
+ };
5406
+ }) => any): this;
5407
+
5408
+ /**
5409
+ * Dispose this agent.
5410
+ */
5411
+ dispose(): Promise<void>;
5412
+
5413
+ /**
5414
+ * Expect certain condition to be met.
5415
+ *
5416
+ * **Usage**
5417
+ *
5418
+ * ```js
5419
+ * await agent.expect('"0 items" to be reported');
5420
+ * ```
5421
+ *
5422
+ * @param expectation Expectation to assert.
5423
+ * @param options
5424
+ */
5425
+ expect(expectation: string, options?: {
5426
+ /**
5427
+ * All the agentic actions are converted to the Playwright calls and are cached. By default, they are cached globally
5428
+ * with the `task` as a key. This option allows controlling the cache key explicitly.
5429
+ */
5430
+ cacheKey?: string;
5431
+
5432
+ /**
5433
+ * Maximum number of retries when generating each action, defaults to context-wide value specified in `agent`
5434
+ * property.
5435
+ */
5436
+ maxActionRetries?: number;
5437
+
5438
+ /**
5439
+ * Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
5440
+ */
5441
+ maxActions?: number;
5442
+
5443
+ /**
5444
+ * Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value.
5445
+ * Defaults to context-wide value specified in `agent` property.
5446
+ */
5447
+ maxTokens?: number;
5448
+
5449
+ /**
5450
+ * Expect timeout in milliseconds. Defaults to `5000`. The default value can be changed via `expect.timeout` option in
5451
+ * the config, or by specifying the `expect` property of the
5452
+ * [`expect`](https://playwright.dev/docs/api/class-page#page-agent-option-expect) option. Pass `0` to disable
5453
+ * timeout.
5454
+ */
5455
+ timeout?: number;
5456
+ }): Promise<void>;
5457
+
5458
+ /**
5459
+ * Perform action using agentic loop.
5460
+ *
5461
+ * **Usage**
5462
+ *
5463
+ * ```js
5464
+ * await agent.perform('Click submit button');
5465
+ * ```
5466
+ *
5467
+ * @param task Task to perform using agentic loop.
5468
+ * @param options
5469
+ */
5470
+ perform(task: string, options?: {
5471
+ /**
5472
+ * All the agentic actions are converted to the Playwright calls and are cached. By default, they are cached globally
5473
+ * with the `task` as a key. This option allows controlling the cache key explicitly.
5474
+ */
5475
+ cacheKey?: string;
5476
+
5477
+ /**
5478
+ * Maximum number of retries when generating each action, defaults to context-wide value specified in `agent`
5479
+ * property.
5480
+ */
5481
+ maxActionRetries?: number;
5482
+
5483
+ /**
5484
+ * Maximum number of agentic actions to generate, defaults to context-wide value specified in `agent` property.
5485
+ */
5486
+ maxActions?: number;
5487
+
5488
+ /**
5489
+ * Maximum number of tokens to consume. The agentic loop will stop after input + output tokens exceed this value.
5490
+ * Defaults to context-wide value specified in `agent` property.
5491
+ */
5492
+ maxTokens?: number;
5493
+
5494
+ /**
5495
+ * Perform timeout in milliseconds. Defaults to `5000`. The default value can be changed via `actionTimeout` option in
5496
+ * the config, or by using the
5497
+ * [browserContext.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-browsercontext#browser-context-set-default-timeout)
5498
+ * or [page.setDefaultTimeout(timeout)](https://playwright.dev/docs/api/class-page#page-set-default-timeout) methods.
5499
+ * Pass `0` to disable timeout.
5500
+ */
5501
+ timeout?: number;
5502
+ }): Promise<{
5503
+ usage: {
5504
+ turns: number;
5505
+
5506
+ inputTokens: number;
5507
+
5508
+ outputTokens: number;
5509
+ };
5510
+ }>;
5511
+
5512
+ /**
5513
+ * Returns the current token usage for this agent.
5514
+ *
5515
+ * **Usage**
5516
+ *
5517
+ * ```js
5518
+ * const usage = await agent.usage();
5519
+ * console.log(`Tokens used: ${usage.inputTokens} in, ${usage.outputTokens} out`);
5520
+ * ```
5521
+ *
5522
+ */
5523
+ usage(): Promise<{
5524
+ turns: number;
5525
+
5526
+ inputTokens: number;
5527
+
5528
+ outputTokens: number;
5529
+ }>;
5530
+
5531
+ [Symbol.asyncDispose](): Promise<void>;
5532
+ }
5533
+
5207
5534
  /**
5208
5535
  * At every point of time, page exposes its current frame tree via the
5209
5536
  * [page.mainFrame()](https://playwright.dev/docs/api/class-page#page-main-frame) and