pageAgent.js 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. var __defProp = Object.defineProperty;
  3. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  4. var __getOwnPropNames = Object.getOwnPropertyNames;
  5. var __hasOwnProp = Object.prototype.hasOwnProperty;
  6. var __export = (target, all) => {
  7. for (var name in all)
  8. __defProp(target, name, { get: all[name], enumerable: true });
  9. };
  10. var __copyProps = (to, from, except, desc) => {
  11. if (from && typeof from === "object" || typeof from === "function") {
  12. for (let key of __getOwnPropNames(from))
  13. if (!__hasOwnProp.call(to, key) && key !== except)
  14. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  15. }
  16. return to;
  17. };
  18. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  19. var pageAgent_exports = {};
  20. __export(pageAgent_exports, {
  21. PageAgent: () => PageAgent
  22. });
  23. module.exports = __toCommonJS(pageAgent_exports);
  24. var import_channelOwner = require("./channelOwner");
  25. var import_events = require("./events");
  26. var import_page = require("./page");
  27. class PageAgent extends import_channelOwner.ChannelOwner {
  28. static from(channel) {
  29. return channel._object;
  30. }
  31. constructor(parent, type, guid, initializer) {
  32. super(parent, type, guid, initializer);
  33. this._page = import_page.Page.from(initializer.page);
  34. this._channel.on("turn", (params) => this.emit(import_events.Events.PageAgent.Turn, params));
  35. }
  36. async expect(expectation, options = {}) {
  37. const timeout = options.timeout ?? this._expectTimeout ?? 5e3;
  38. await this._channel.expect({ expectation, ...options, timeout });
  39. }
  40. async perform(task, options = {}) {
  41. const timeout = this._page._timeoutSettings.timeout(options);
  42. const { usage } = await this._channel.perform({ task, ...options, timeout });
  43. return { usage };
  44. }
  45. async extract(query, schema, options = {}) {
  46. const timeout = this._page._timeoutSettings.timeout(options);
  47. const { result, usage } = await this._channel.extract({ query, schema: this._page._platform.zodToJsonSchema(schema), ...options, timeout });
  48. return { result, usage };
  49. }
  50. async usage() {
  51. const { usage } = await this._channel.usage({});
  52. return usage;
  53. }
  54. async dispose() {
  55. await this._channel.dispose();
  56. }
  57. async [Symbol.asyncDispose]() {
  58. await this.dispose();
  59. }
  60. }
  61. // Annotate the CommonJS export names for ESM import in node:
  62. 0 && (module.exports = {
  63. PageAgent
  64. });