video.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 video_exports = {};
  20. __export(video_exports, {
  21. Video: () => Video
  22. });
  23. module.exports = __toCommonJS(video_exports);
  24. var import_manualPromise = require("../utils/isomorphic/manualPromise");
  25. class Video {
  26. constructor(page, connection) {
  27. this._artifact = null;
  28. this._artifactReadyPromise = new import_manualPromise.ManualPromise();
  29. this._isRemote = false;
  30. this._isRemote = connection.isRemote();
  31. this._artifact = page._closedOrCrashedScope.safeRace(this._artifactReadyPromise);
  32. }
  33. _artifactReady(artifact) {
  34. this._artifactReadyPromise.resolve(artifact);
  35. }
  36. async path() {
  37. if (this._isRemote)
  38. throw new Error(`Path is not available when connecting remotely. Use saveAs() to save a local copy.`);
  39. const artifact = await this._artifact;
  40. if (!artifact)
  41. throw new Error("Page did not produce any video frames");
  42. return artifact._initializer.absolutePath;
  43. }
  44. async saveAs(path) {
  45. const artifact = await this._artifact;
  46. if (!artifact)
  47. throw new Error("Page did not produce any video frames");
  48. return await artifact.saveAs(path);
  49. }
  50. async delete() {
  51. const artifact = await this._artifact;
  52. if (artifact)
  53. await artifact.delete();
  54. }
  55. }
  56. // Annotate the CommonJS export names for ESM import in node:
  57. 0 && (module.exports = {
  58. Video
  59. });