tracing.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 tracing_exports = {};
  20. __export(tracing_exports, {
  21. default: () => tracing_default
  22. });
  23. module.exports = __toCommonJS(tracing_exports);
  24. var import_bundle = require("../../sdk/bundle");
  25. var import_tool = require("./tool");
  26. const tracingStart = (0, import_tool.defineTool)({
  27. capability: "tracing",
  28. schema: {
  29. name: "browser_start_tracing",
  30. title: "Start tracing",
  31. description: "Start trace recording",
  32. inputSchema: import_bundle.z.object({}),
  33. type: "readOnly"
  34. },
  35. handle: async (context, params, response) => {
  36. const browserContext = await context.ensureBrowserContext();
  37. const tracesDir = await context.outputFile(`traces`, { origin: "code", reason: "Collecting trace" });
  38. const name = "trace-" + Date.now();
  39. await browserContext.tracing.start({
  40. name,
  41. screenshots: true,
  42. snapshots: true,
  43. _live: true
  44. });
  45. const traceLegend = `- Action log: ${tracesDir}/${name}.trace
  46. - Network log: ${tracesDir}/${name}.network
  47. - Resources with content by sha1: ${tracesDir}/resources`;
  48. response.addResult(`Tracing started, saving to ${tracesDir}.
  49. ${traceLegend}`);
  50. browserContext.tracing[traceLegendSymbol] = traceLegend;
  51. }
  52. });
  53. const tracingStop = (0, import_tool.defineTool)({
  54. capability: "tracing",
  55. schema: {
  56. name: "browser_stop_tracing",
  57. title: "Stop tracing",
  58. description: "Stop trace recording",
  59. inputSchema: import_bundle.z.object({}),
  60. type: "readOnly"
  61. },
  62. handle: async (context, params, response) => {
  63. const browserContext = await context.ensureBrowserContext();
  64. await browserContext.tracing.stop();
  65. const traceLegend = browserContext.tracing[traceLegendSymbol];
  66. response.addResult(`Tracing stopped.
  67. ${traceLegend}`);
  68. }
  69. });
  70. var tracing_default = [
  71. tracingStart,
  72. tracingStop
  73. ];
  74. const traceLegendSymbol = Symbol("tracesDir");