download.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  5. var __getOwnPropNames = Object.getOwnPropertyNames;
  6. var __getProtoOf = Object.getPrototypeOf;
  7. var __hasOwnProp = Object.prototype.hasOwnProperty;
  8. var __export = (target, all) => {
  9. for (var name in all)
  10. __defProp(target, name, { get: all[name], enumerable: true });
  11. };
  12. var __copyProps = (to, from, except, desc) => {
  13. if (from && typeof from === "object" || typeof from === "function") {
  14. for (let key of __getOwnPropNames(from))
  15. if (!__hasOwnProp.call(to, key) && key !== except)
  16. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  17. }
  18. return to;
  19. };
  20. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  21. // If the importer is in node compatibility mode or this is not an ESM
  22. // file that has been converted to a CommonJS file using a Babel-
  23. // compatible transform (i.e. "__esModule" has not been set), then set
  24. // "default" to the CommonJS "module.exports" for node compatibility.
  25. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  26. mod
  27. ));
  28. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  29. var download_exports = {};
  30. __export(download_exports, {
  31. Download: () => Download
  32. });
  33. module.exports = __toCommonJS(download_exports);
  34. var import_path = __toESM(require("path"));
  35. var import_page = require("./page");
  36. var import_utils = require("../utils");
  37. var import_artifact = require("./artifact");
  38. class Download {
  39. constructor(page, downloadsPath, uuid, url, suggestedFilename) {
  40. const unaccessibleErrorMessage = page.browserContext._options.acceptDownloads === "deny" ? "Pass { acceptDownloads: true } when you are creating your browser context." : void 0;
  41. this.artifact = new import_artifact.Artifact(page, import_path.default.join(downloadsPath, uuid), unaccessibleErrorMessage, () => {
  42. return this._page.browserContext.cancelDownload(uuid);
  43. });
  44. this._page = page;
  45. this.url = url;
  46. this._suggestedFilename = suggestedFilename;
  47. page.browserContext._downloads.add(this);
  48. if (suggestedFilename !== void 0)
  49. this._fireDownloadEvent();
  50. }
  51. page() {
  52. return this._page;
  53. }
  54. _filenameSuggested(suggestedFilename) {
  55. (0, import_utils.assert)(this._suggestedFilename === void 0);
  56. this._suggestedFilename = suggestedFilename;
  57. this._fireDownloadEvent();
  58. }
  59. suggestedFilename() {
  60. return this._suggestedFilename;
  61. }
  62. _fireDownloadEvent() {
  63. this._page.instrumentation.onDownload(this._page, this);
  64. this._page.emit(import_page.Page.Events.Download, this);
  65. }
  66. }
  67. // Annotate the CommonJS export names for ESM import in node:
  68. 0 && (module.exports = {
  69. Download
  70. });