clientStackTrace.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 clientStackTrace_exports = {};
  20. __export(clientStackTrace_exports, {
  21. captureLibraryStackTrace: () => captureLibraryStackTrace
  22. });
  23. module.exports = __toCommonJS(clientStackTrace_exports);
  24. var import_stackTrace = require("../utils/isomorphic/stackTrace");
  25. function captureLibraryStackTrace(platform) {
  26. const stack = (0, import_stackTrace.captureRawStack)();
  27. let parsedFrames = stack.map((line) => {
  28. const frame = (0, import_stackTrace.parseStackFrame)(line, platform.pathSeparator, platform.showInternalStackFrames());
  29. if (!frame || !frame.file)
  30. return null;
  31. const isPlaywrightLibrary = !!platform.coreDir && frame.file.startsWith(platform.coreDir);
  32. const parsed = {
  33. frame,
  34. frameText: line,
  35. isPlaywrightLibrary
  36. };
  37. return parsed;
  38. }).filter(Boolean);
  39. let apiName = "";
  40. for (let i = 0; i < parsedFrames.length - 1; i++) {
  41. const parsedFrame = parsedFrames[i];
  42. if (parsedFrame.isPlaywrightLibrary && !parsedFrames[i + 1].isPlaywrightLibrary) {
  43. apiName = apiName || normalizeAPIName(parsedFrame.frame.function);
  44. break;
  45. }
  46. }
  47. function normalizeAPIName(name) {
  48. if (!name)
  49. return "";
  50. const match = name.match(/(API|JS|CDP|[A-Z])(.*)/);
  51. if (!match)
  52. return name;
  53. return match[1].toLowerCase() + match[2];
  54. }
  55. const filterPrefixes = platform.boxedStackPrefixes();
  56. parsedFrames = parsedFrames.filter((f) => {
  57. if (filterPrefixes.some((prefix) => f.frame.file.startsWith(prefix)))
  58. return false;
  59. return true;
  60. });
  61. return {
  62. frames: parsedFrames.map((p) => p.frame),
  63. apiName
  64. };
  65. }
  66. // Annotate the CommonJS export names for ESM import in node:
  67. 0 && (module.exports = {
  68. captureLibraryStackTrace
  69. });