@wordpress/e2e-test-utils-playwright 1.32.0 → 1.32.1-next.ff1cebbba.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/build/admin/create-new-post.js +46 -28
  2. package/build/admin/create-new-post.js.map +7 -1
  3. package/build/admin/edit-post.js +35 -17
  4. package/build/admin/edit-post.js.map +7 -1
  5. package/build/admin/get-page-error.js +30 -22
  6. package/build/admin/get-page-error.js.map +7 -1
  7. package/build/admin/index.js +54 -34
  8. package/build/admin/index.js.map +7 -1
  9. package/build/admin/visit-admin-page.js +42 -29
  10. package/build/admin/visit-admin-page.js.map +7 -1
  11. package/build/admin/visit-site-editor.js +71 -64
  12. package/build/admin/visit-site-editor.js.map +7 -1
  13. package/build/config.js +40 -10
  14. package/build/config.js.map +7 -1
  15. package/build/editor/click-block-options-menu-item.js +29 -14
  16. package/build/editor/click-block-options-menu-item.js.map +7 -1
  17. package/build/editor/click-block-toolbar-button.js +33 -13
  18. package/build/editor/click-block-toolbar-button.js.map +7 -1
  19. package/build/editor/get-blocks.js +59 -43
  20. package/build/editor/get-blocks.js.map +7 -1
  21. package/build/editor/get-edited-post-content.js +31 -12
  22. package/build/editor/get-edited-post-content.js.map +7 -1
  23. package/build/editor/index.js +92 -72
  24. package/build/editor/index.js.map +7 -1
  25. package/build/editor/insert-block.js +50 -21
  26. package/build/editor/insert-block.js.map +7 -1
  27. package/build/editor/open-document-settings-sidebar.js +37 -24
  28. package/build/editor/open-document-settings-sidebar.js.map +7 -1
  29. package/build/editor/preview.js +37 -18
  30. package/build/editor/preview.js.map +7 -1
  31. package/build/editor/publish-post.js +42 -42
  32. package/build/editor/publish-post.js.map +7 -1
  33. package/build/editor/save-draft.js +29 -15
  34. package/build/editor/save-draft.js.map +7 -1
  35. package/build/editor/select-blocks.js +46 -25
  36. package/build/editor/select-blocks.js.map +7 -1
  37. package/build/editor/set-content.js +34 -14
  38. package/build/editor/set-content.js.map +7 -1
  39. package/build/editor/set-is-fixed-toolbar.js +31 -15
  40. package/build/editor/set-is-fixed-toolbar.js.map +7 -1
  41. package/build/editor/set-preferences.js +38 -18
  42. package/build/editor/set-preferences.js.map +7 -1
  43. package/build/editor/show-block-toolbar.js +30 -16
  44. package/build/editor/show-block-toolbar.js.map +7 -1
  45. package/build/editor/site-editor.js +46 -41
  46. package/build/editor/site-editor.js.map +7 -1
  47. package/build/editor/switch-editor-tool.js +42 -30
  48. package/build/editor/switch-editor-tool.js.map +7 -1
  49. package/build/editor/switch-to-legacy-canvas.js +33 -14
  50. package/build/editor/switch-to-legacy-canvas.js.map +7 -1
  51. package/build/editor/transform-block-to.js +41 -21
  52. package/build/editor/transform-block-to.js.map +7 -1
  53. package/build/index.js +50 -32
  54. package/build/index.js.map +7 -1
  55. package/build/lighthouse/index.js +89 -53
  56. package/build/lighthouse/index.js.map +7 -1
  57. package/build/metrics/index.js +298 -249
  58. package/build/metrics/index.js.map +7 -1
  59. package/build/page-utils/drag-files.js +134 -112
  60. package/build/page-utils/drag-files.js.map +7 -1
  61. package/build/page-utils/emulate-network-conditions.js +92 -66
  62. package/build/page-utils/emulate-network-conditions.js.map +7 -1
  63. package/build/page-utils/index.js +54 -34
  64. package/build/page-utils/index.js.map +7 -1
  65. package/build/page-utils/is-current-url.js +31 -18
  66. package/build/page-utils/is-current-url.js.map +7 -1
  67. package/build/page-utils/keycodes.js +51 -39
  68. package/build/page-utils/keycodes.js.map +7 -1
  69. package/build/page-utils/press-keys.js +148 -127
  70. package/build/page-utils/press-keys.js.map +7 -1
  71. package/build/page-utils/set-browser-viewport.js +32 -41
  72. package/build/page-utils/set-browser-viewport.js.map +7 -1
  73. package/build/request-utils/blocks.js +49 -40
  74. package/build/request-utils/blocks.js.map +7 -1
  75. package/build/request-utils/comments.js +57 -45
  76. package/build/request-utils/comments.js.map +7 -1
  77. package/build/request-utils/gutenberg-experiments.js +48 -26
  78. package/build/request-utils/gutenberg-experiments.js.map +7 -1
  79. package/build/request-utils/index.js +187 -153
  80. package/build/request-utils/index.js.map +7 -1
  81. package/build/request-utils/login.js +43 -18
  82. package/build/request-utils/login.js.map +7 -1
  83. package/build/request-utils/media.js +72 -64
  84. package/build/request-utils/media.js.map +7 -1
  85. package/build/request-utils/menus.js +119 -109
  86. package/build/request-utils/menus.js.map +7 -1
  87. package/build/request-utils/pages.js +60 -49
  88. package/build/request-utils/pages.js.map +7 -1
  89. package/build/request-utils/patterns.js +39 -24
  90. package/build/request-utils/patterns.js.map +7 -1
  91. package/build/request-utils/plugins.js +68 -74
  92. package/build/request-utils/plugins.js.map +7 -1
  93. package/build/request-utils/posts.js +52 -39
  94. package/build/request-utils/posts.js.map +7 -1
  95. package/build/request-utils/preferences.js +36 -17
  96. package/build/request-utils/preferences.js.map +7 -1
  97. package/build/request-utils/rest.js +153 -129
  98. package/build/request-utils/rest.js.map +7 -1
  99. package/build/request-utils/site-settings.js +38 -28
  100. package/build/request-utils/site-settings.js.map +7 -1
  101. package/build/request-utils/templates.js +57 -45
  102. package/build/request-utils/templates.js.map +7 -1
  103. package/build/request-utils/themes.js +78 -53
  104. package/build/request-utils/themes.js.map +7 -1
  105. package/build/request-utils/users.js +72 -72
  106. package/build/request-utils/users.js.map +7 -1
  107. package/build/request-utils/widgets.js +71 -55
  108. package/build/request-utils/widgets.js.map +7 -1
  109. package/build/test.js +128 -146
  110. package/build/test.js.map +7 -1
  111. package/build/types.js +16 -2
  112. package/build/types.js.map +7 -1
  113. package/package.json +6 -2
@@ -1,119 +1,141 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.dragFiles = dragFiles;
4
- /**
5
- * External dependencies
6
- */
7
- const promises_1 = require("fs/promises");
8
- const path_1 = require("path");
9
- const mime_1 = require("mime");
10
- /**
11
- * Simulate dragging files from outside the current page.
12
- *
13
- * @param this
14
- * @param files The files to be dragged.
15
- * @return The methods of the drag operation.
16
- */
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 drag_files_exports = {};
20
+ __export(drag_files_exports, {
21
+ dragFiles: () => dragFiles
22
+ });
23
+ module.exports = __toCommonJS(drag_files_exports);
24
+ var import_promises = require("fs/promises");
25
+ var import_path = require("path");
26
+ var import_mime = require("mime");
17
27
  async function dragFiles(files) {
18
- const filesList = Array.isArray(files) ? files : [files];
19
- const fileObjects = await Promise.all(filesList.map(async (filePathOrObject) => {
20
- if (typeof filePathOrObject !== 'string') {
21
- return {
22
- name: filePathOrObject.name,
23
- mimeType: filePathOrObject.mimeType ||
24
- (0, mime_1.getType)(filePathOrObject.name),
25
- base64: filePathOrObject.buffer.toString('base64'),
26
- };
27
- }
28
- const base64 = await (0, promises_1.readFile)(filePathOrObject, 'base64');
29
- const name = (0, path_1.basename)(filePathOrObject);
28
+ const filesList = Array.isArray(files) ? files : [files];
29
+ const fileObjects = await Promise.all(
30
+ filesList.map(async (filePathOrObject) => {
31
+ if (typeof filePathOrObject !== "string") {
30
32
  return {
31
- name,
32
- mimeType: (0, mime_1.getType)(filePathOrObject),
33
- base64,
33
+ name: filePathOrObject.name,
34
+ mimeType: filePathOrObject.mimeType || (0, import_mime.getType)(filePathOrObject.name),
35
+ base64: filePathOrObject.buffer.toString("base64")
34
36
  };
35
- }));
36
- // CDP doesn't actually support dragging files, this is only a _good enough_
37
- // dummy data so that it will correctly send the relevant events.
38
- const dragData = {
39
- items: fileObjects.map((fileObject) => ({
40
- mimeType: fileObject.mimeType ?? 'File',
41
- data: fileObject.base64,
42
- })),
43
- files: fileObjects.map((fileObject) => fileObject.name),
44
- // Copy = 1, Link = 2, Move = 16.
45
- dragOperationsMask: 1,
46
- };
47
- const cdpSession = await this.context.newCDPSession(this.page);
48
- const position = {
49
- x: 0,
50
- y: 0,
51
- };
52
- return {
53
- /**
54
- * Drag the files over an element (fires `dragenter` and `dragover` events).
55
- *
56
- * @param selectorOrLocator A selector or a locator to search for an element.
57
- * @param options The optional options.
58
- * @param options.position A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
59
- */
60
- dragOver: async (selectorOrLocator, options = {}) => {
61
- const locator = typeof selectorOrLocator === 'string'
62
- ? this.page.locator(selectorOrLocator)
63
- : selectorOrLocator;
64
- const boundingBox = await locator.boundingBox();
65
- if (!boundingBox) {
66
- throw new Error('Cannot find the element or the element is not visible on the viewport.');
67
- }
68
- position.x =
69
- boundingBox.x +
70
- (options.position?.x ?? boundingBox.width / 2);
71
- position.y =
72
- boundingBox.y +
73
- (options.position?.y ?? boundingBox.height / 2);
74
- await cdpSession.send('Input.dispatchDragEvent', {
75
- type: 'dragEnter',
76
- ...position,
77
- data: dragData,
78
- });
79
- await cdpSession.send('Input.dispatchDragEvent', {
80
- type: 'dragOver',
81
- ...position,
82
- data: dragData,
83
- });
37
+ }
38
+ const base64 = await (0, import_promises.readFile)(filePathOrObject, "base64");
39
+ const name = (0, import_path.basename)(filePathOrObject);
40
+ return {
41
+ name,
42
+ mimeType: (0, import_mime.getType)(filePathOrObject),
43
+ base64
44
+ };
45
+ })
46
+ );
47
+ const dragData = {
48
+ items: fileObjects.map((fileObject) => ({
49
+ mimeType: fileObject.mimeType ?? "File",
50
+ data: fileObject.base64
51
+ })),
52
+ files: fileObjects.map((fileObject) => fileObject.name),
53
+ // Copy = 1, Link = 2, Move = 16.
54
+ dragOperationsMask: 1
55
+ };
56
+ const cdpSession = await this.context.newCDPSession(this.page);
57
+ const position = {
58
+ x: 0,
59
+ y: 0
60
+ };
61
+ return {
62
+ /**
63
+ * Drag the files over an element (fires `dragenter` and `dragover` events).
64
+ *
65
+ * @param selectorOrLocator A selector or a locator to search for an element.
66
+ * @param options The optional options.
67
+ * @param options.position A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.
68
+ */
69
+ dragOver: async (selectorOrLocator, options = {}) => {
70
+ const locator = typeof selectorOrLocator === "string" ? this.page.locator(selectorOrLocator) : selectorOrLocator;
71
+ const boundingBox = await locator.boundingBox();
72
+ if (!boundingBox) {
73
+ throw new Error(
74
+ "Cannot find the element or the element is not visible on the viewport."
75
+ );
76
+ }
77
+ position.x = boundingBox.x + (options.position?.x ?? boundingBox.width / 2);
78
+ position.y = boundingBox.y + (options.position?.y ?? boundingBox.height / 2);
79
+ await cdpSession.send("Input.dispatchDragEvent", {
80
+ type: "dragEnter",
81
+ ...position,
82
+ data: dragData
83
+ });
84
+ await cdpSession.send("Input.dispatchDragEvent", {
85
+ type: "dragOver",
86
+ ...position,
87
+ data: dragData
88
+ });
89
+ },
90
+ /**
91
+ * Drop the files at the current position.
92
+ */
93
+ drop: async () => {
94
+ const topMostElement = await this.page.evaluateHandle(
95
+ ({ x, y }) => {
96
+ const element = document.elementFromPoint(x, y);
97
+ if (element instanceof HTMLIFrameElement) {
98
+ const offsetBox = element.getBoundingClientRect();
99
+ return element.contentDocument.elementFromPoint(
100
+ x - offsetBox.x,
101
+ y - offsetBox.y
102
+ );
103
+ }
104
+ return element;
84
105
  },
85
- /**
86
- * Drop the files at the current position.
87
- */
88
- drop: async () => {
89
- const topMostElement = await this.page.evaluateHandle(({ x, y }) => {
90
- const element = document.elementFromPoint(x, y);
91
- if (element instanceof HTMLIFrameElement) {
92
- const offsetBox = element.getBoundingClientRect();
93
- return element.contentDocument.elementFromPoint(x - offsetBox.x, y - offsetBox.y);
94
- }
95
- return element;
96
- }, position);
97
- const elementHandle = topMostElement.asElement();
98
- if (!elementHandle) {
99
- throw new Error('Element not found.');
100
- }
101
- const dataTransfer = await elementHandle.evaluateHandle(async (_node, _fileObjects) => {
102
- const dt = new DataTransfer();
103
- const fileInstances = await Promise.all(_fileObjects.map(async (fileObject) => {
104
- const blob = await fetch(`data:${fileObject.mimeType};base64,${fileObject.base64}`).then((res) => res.blob());
105
- return new File([blob], fileObject.name, {
106
- type: fileObject.mimeType ?? undefined,
107
- });
108
- }));
109
- fileInstances.forEach((file) => {
110
- dt.items.add(file);
111
- });
112
- return dt;
113
- }, fileObjects);
114
- await elementHandle.dispatchEvent('drop', { dataTransfer });
115
- await cdpSession.detach();
106
+ position
107
+ );
108
+ const elementHandle = topMostElement.asElement();
109
+ if (!elementHandle) {
110
+ throw new Error("Element not found.");
111
+ }
112
+ const dataTransfer = await elementHandle.evaluateHandle(
113
+ async (_node, _fileObjects) => {
114
+ const dt = new DataTransfer();
115
+ const fileInstances = await Promise.all(
116
+ _fileObjects.map(async (fileObject) => {
117
+ const blob = await fetch(
118
+ `data:${fileObject.mimeType};base64,${fileObject.base64}`
119
+ ).then((res) => res.blob());
120
+ return new File([blob], fileObject.name, {
121
+ type: fileObject.mimeType ?? void 0
122
+ });
123
+ })
124
+ );
125
+ fileInstances.forEach((file) => {
126
+ dt.items.add(file);
127
+ });
128
+ return dt;
116
129
  },
117
- };
130
+ fileObjects
131
+ );
132
+ await elementHandle.dispatchEvent("drop", { dataTransfer });
133
+ await cdpSession.detach();
134
+ }
135
+ };
118
136
  }
119
- //# sourceMappingURL=drag-files.js.map
137
+ // Annotate the CommonJS export names for ESM import in node:
138
+ 0 && (module.exports = {
139
+ dragFiles
140
+ });
141
+ //# sourceMappingURL=drag-files.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"drag-files.js","sourceRoot":"","sources":["../../src/page-utils/drag-files.ts"],"names":[],"mappings":";;AA4KS,8BAAS;AA5KlB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BAC3C,IAAI,EAAE,UAAU,CAAC,QAAQ,IAAI,SAAS;qBACtC,CAAE,CAAC;gBACL,CAAC,CAAE,CACH,CAAC;gBAEF,aAAa,CAAC,OAAO,CAAE,CAAE,IAAI,EAAG,EAAE;oBACjC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAE,IAAI,CAAE,CAAC;gBACtB,CAAC,CAAE,CAAC;gBAEJ,OAAO,EAAE,CAAC;YACX,CAAC,EACD,WAAW,CACX,CAAC;YAEF,MAAM,aAAa,CAAC,aAAa,CAAE,MAAM,EAAE,EAAE,YAAY,EAAE,CAAE,CAAC;YAE9D,MAAM,UAAU,CAAC,MAAM,EAAE,CAAC;QAC3B,CAAC;KACD,CAAC;AACH,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/page-utils/drag-files.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { readFile } from 'fs/promises';\nimport { basename } from 'path';\nimport { getType } from 'mime';\n\n/**\n * Internal dependencies\n */\nimport type { PageUtils } from './index';\nimport type { Locator } from '@playwright/test';\n\ntype FileObject = {\n\tname: string;\n\tmimeType?: string;\n\tbuffer: Buffer;\n};\n\ntype Options = {\n\tposition?: { x: number; y: number };\n};\n\n/**\n * Simulate dragging files from outside the current page.\n *\n * @param this\n * @param files The files to be dragged.\n * @return The methods of the drag operation.\n */\nasync function dragFiles(\n\tthis: PageUtils,\n\tfiles: string | string[] | FileObject | FileObject[]\n) {\n\tconst filesList = Array.isArray( files ) ? files : [ files ];\n\tconst fileObjects = await Promise.all(\n\t\tfilesList.map( async ( filePathOrObject ) => {\n\t\t\tif ( typeof filePathOrObject !== 'string' ) {\n\t\t\t\treturn {\n\t\t\t\t\tname: filePathOrObject.name,\n\t\t\t\t\tmimeType:\n\t\t\t\t\t\tfilePathOrObject.mimeType ||\n\t\t\t\t\t\tgetType( filePathOrObject.name ),\n\t\t\t\t\tbase64: filePathOrObject.buffer.toString( 'base64' ),\n\t\t\t\t};\n\t\t\t}\n\t\t\tconst base64 = await readFile( filePathOrObject, 'base64' );\n\t\t\tconst name = basename( filePathOrObject );\n\t\t\treturn {\n\t\t\t\tname,\n\t\t\t\tmimeType: getType( filePathOrObject ),\n\t\t\t\tbase64,\n\t\t\t};\n\t\t} )\n\t);\n\n\t// CDP doesn't actually support dragging files, this is only a _good enough_\n\t// dummy data so that it will correctly send the relevant events.\n\tconst dragData = {\n\t\titems: fileObjects.map( ( fileObject ) => ( {\n\t\t\tmimeType: fileObject.mimeType ?? 'File',\n\t\t\tdata: fileObject.base64,\n\t\t} ) ),\n\t\tfiles: fileObjects.map( ( fileObject ) => fileObject.name ),\n\t\t// Copy = 1, Link = 2, Move = 16.\n\t\tdragOperationsMask: 1,\n\t};\n\n\tconst cdpSession = await this.context.newCDPSession( this.page );\n\n\tconst position = {\n\t\tx: 0,\n\t\ty: 0,\n\t};\n\n\treturn {\n\t\t/**\n\t\t * Drag the files over an element (fires `dragenter` and `dragover` events).\n\t\t *\n\t\t * @param selectorOrLocator A selector or a locator to search for an element.\n\t\t * @param options The optional options.\n\t\t * @param options.position A point to use relative to the top-left corner of element padding box. If not specified, uses some visible point of the element.\n\t\t */\n\t\tdragOver: async (\n\t\t\tselectorOrLocator: string | Locator,\n\t\t\toptions: Options = {}\n\t\t) => {\n\t\t\tconst locator =\n\t\t\t\ttypeof selectorOrLocator === 'string'\n\t\t\t\t\t? this.page.locator( selectorOrLocator )\n\t\t\t\t\t: selectorOrLocator;\n\t\t\tconst boundingBox = await locator.boundingBox();\n\n\t\t\tif ( ! boundingBox ) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Cannot find the element or the element is not visible on the viewport.'\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tposition.x =\n\t\t\t\tboundingBox.x +\n\t\t\t\t( options.position?.x ?? boundingBox.width / 2 );\n\t\t\tposition.y =\n\t\t\t\tboundingBox.y +\n\t\t\t\t( options.position?.y ?? boundingBox.height / 2 );\n\n\t\t\tawait cdpSession.send( 'Input.dispatchDragEvent', {\n\t\t\t\ttype: 'dragEnter',\n\t\t\t\t...position,\n\t\t\t\tdata: dragData,\n\t\t\t} );\n\t\t\tawait cdpSession.send( 'Input.dispatchDragEvent', {\n\t\t\t\ttype: 'dragOver',\n\t\t\t\t...position,\n\t\t\t\tdata: dragData,\n\t\t\t} );\n\t\t},\n\n\t\t/**\n\t\t * Drop the files at the current position.\n\t\t */\n\t\tdrop: async () => {\n\t\t\tconst topMostElement = await this.page.evaluateHandle(\n\t\t\t\t( { x, y } ) => {\n\t\t\t\t\tconst element = document.elementFromPoint( x, y );\n\t\t\t\t\tif ( element instanceof HTMLIFrameElement ) {\n\t\t\t\t\t\tconst offsetBox = element.getBoundingClientRect();\n\t\t\t\t\t\treturn element.contentDocument!.elementFromPoint(\n\t\t\t\t\t\t\tx - offsetBox.x,\n\t\t\t\t\t\t\ty - offsetBox.y\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\treturn element;\n\t\t\t\t},\n\t\t\t\tposition\n\t\t\t);\n\t\t\tconst elementHandle = topMostElement.asElement();\n\n\t\t\tif ( ! elementHandle ) {\n\t\t\t\tthrow new Error( 'Element not found.' );\n\t\t\t}\n\n\t\t\tconst dataTransfer = await elementHandle.evaluateHandle(\n\t\t\t\tasync ( _node, _fileObjects ) => {\n\t\t\t\t\tconst dt = new DataTransfer();\n\t\t\t\t\tconst fileInstances = await Promise.all(\n\t\t\t\t\t\t_fileObjects.map( async ( fileObject: any ) => {\n\t\t\t\t\t\t\tconst blob = await fetch(\n\t\t\t\t\t\t\t\t`data:${ fileObject.mimeType };base64,${ fileObject.base64 }`\n\t\t\t\t\t\t\t).then( ( res ) => res.blob() );\n\t\t\t\t\t\t\treturn new File( [ blob ], fileObject.name, {\n\t\t\t\t\t\t\t\ttype: fileObject.mimeType ?? undefined,\n\t\t\t\t\t\t\t} );\n\t\t\t\t\t\t} )\n\t\t\t\t\t);\n\n\t\t\t\t\tfileInstances.forEach( ( file ) => {\n\t\t\t\t\t\tdt.items.add( file );\n\t\t\t\t\t} );\n\n\t\t\t\t\treturn dt;\n\t\t\t\t},\n\t\t\t\tfileObjects\n\t\t\t);\n\n\t\t\tawait elementHandle.dispatchEvent( 'drop', { dataTransfer } );\n\n\t\t\tawait cdpSession.detach();\n\t\t},\n\t};\n}\n\nexport { dragFiles };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAyB;AACzB,kBAAyB;AACzB,kBAAwB;AAyBxB,eAAe,UAEd,OACC;AACD,QAAM,YAAY,MAAM,QAAS,KAAM,IAAI,QAAQ,CAAE,KAAM;AAC3D,QAAM,cAAc,MAAM,QAAQ;AAAA,IACjC,UAAU,IAAK,OAAQ,qBAAsB;AAC5C,UAAK,OAAO,qBAAqB,UAAW;AAC3C,eAAO;AAAA,UACN,MAAM,iBAAiB;AAAA,UACvB,UACC,iBAAiB,gBACjB,qBAAS,iBAAiB,IAAK;AAAA,UAChC,QAAQ,iBAAiB,OAAO,SAAU,QAAS;AAAA,QACpD;AAAA,MACD;AACA,YAAM,SAAS,UAAM,0BAAU,kBAAkB,QAAS;AAC1D,YAAM,WAAO,sBAAU,gBAAiB;AACxC,aAAO;AAAA,QACN;AAAA,QACA,cAAU,qBAAS,gBAAiB;AAAA,QACpC;AAAA,MACD;AAAA,IACD,CAAE;AAAA,EACH;AAIA,QAAM,WAAW;AAAA,IAChB,OAAO,YAAY,IAAK,CAAE,gBAAkB;AAAA,MAC3C,UAAU,WAAW,YAAY;AAAA,MACjC,MAAM,WAAW;AAAA,IAClB,EAAI;AAAA,IACJ,OAAO,YAAY,IAAK,CAAE,eAAgB,WAAW,IAAK;AAAA;AAAA,IAE1D,oBAAoB;AAAA,EACrB;AAEA,QAAM,aAAa,MAAM,KAAK,QAAQ,cAAe,KAAK,IAAK;AAE/D,QAAM,WAAW;AAAA,IAChB,GAAG;AAAA,IACH,GAAG;AAAA,EACJ;AAEA,SAAO;AAAA;AA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OAAQ,eAAqB;AAC9C,oBAAM,OAAO,MAAM;AAAA,gBAClB,QAAS,WAAW,QAAS,WAAY,WAAW,MAAO;AAAA,cAC5D,EAAE,KAAM,CAAE,QAAS,IAAI,KAAK,CAAE;AAC9B,qBAAO,IAAI,KAAM,CAAE,IAAK,GAAG,WAAW,MAAM;AAAA,gBAC3C,MAAM,WAAW,YAAY;AAAA,cAC9B,CAAE;AAAA,YACH,CAAE;AAAA,UACH;AAEA,wBAAc,QAAS,CAAE,SAAU;AAClC,eAAG,MAAM,IAAK,IAAK;AAAA,UACpB,CAAE;AAEF,iBAAO;AAAA,QACR;AAAA,QACA;AAAA,MACD;AAEA,YAAM,cAAc,cAAe,QAAQ,EAAE,aAAa,CAAE;AAE5D,YAAM,WAAW,OAAO;AAAA,IACzB;AAAA,EACD;AACD;",
6
+ "names": []
7
+ }
@@ -1,71 +1,97 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.emulateNetworkConditions = emulateNetworkConditions;
4
- // Defaults from https://github.com/puppeteer/puppeteer/blob/401355610874beac23a51dcb75739a4bb4191a2b/packages/puppeteer-core/src/cdp/PredefinedNetworkConditions.ts.
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 emulate_network_conditions_exports = {};
20
+ __export(emulate_network_conditions_exports, {
21
+ emulateNetworkConditions: () => emulateNetworkConditions
22
+ });
23
+ module.exports = __toCommonJS(emulate_network_conditions_exports);
5
24
  const PredefinedNetworkConditions = {
6
- // Generally aligned with DevTools
7
- // https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.
8
- 'Slow 3G': {
9
- offline: false,
10
- // ~500Kbps down
11
- downloadThroughput: ((500 * 1000) / 8) * 0.8,
12
- // ~500Kbps up
13
- uploadThroughput: ((500 * 1000) / 8) * 0.8,
14
- // 400ms RTT
15
- latency: 400 * 5,
16
- },
17
- 'Fast 3G': {
18
- offline: false,
19
- // ~1.6 Mbps down
20
- downloadThroughput: ((1.6 * 1000 * 1000) / 8) * 0.9,
21
- // ~0.75 Mbps up
22
- uploadThroughput: ((750 * 1000) / 8) * 0.9,
23
- // 150ms RTT
24
- latency: 150 * 3.75,
25
- },
26
- // alias to Fast 3G to align with Lighthouse (crbug.com/342406608)
27
- // and DevTools (crbug.com/342406608),
28
- 'Slow 4G': {
29
- offline: false,
30
- // ~1.6 Mbps down
31
- downloadThroughput: ((1.6 * 1000 * 1000) / 8) * 0.9,
32
- // ~0.75 Mbps up
33
- uploadThroughput: ((750 * 1000) / 8) * 0.9,
34
- // 150ms RTT
35
- latency: 150 * 3.75,
36
- },
37
- 'Fast 4G': {
38
- offline: false,
39
- // 9 Mbps down
40
- downloadThroughput: ((9 * 1000 * 1000) / 8) * 0.9,
41
- // 1.5 Mbps up
42
- uploadThroughput: ((1.5 * 1000 * 1000) / 8) * 0.9,
43
- // 60ms RTT
44
- latency: 60 * 2.75,
45
- },
46
- /**
47
- * Network conditions used for desktop in Lighthouse/PSI.
48
- *
49
- * 10,240 kb/s throughput with 40 ms TCP RTT.
50
- *
51
- * @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49
52
- * @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6
53
- */
54
- Broadband: {
55
- offline: false,
56
- downloadThroughput: (10240 * 1000) / 8,
57
- uploadThroughput: (10240 * 1000) / 8,
58
- latency: 40,
59
- },
25
+ // Generally aligned with DevTools
26
+ // https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.
27
+ "Slow 3G": {
28
+ offline: false,
29
+ // ~500Kbps down
30
+ downloadThroughput: 500 * 1e3 / 8 * 0.8,
31
+ // ~500Kbps up
32
+ uploadThroughput: 500 * 1e3 / 8 * 0.8,
33
+ // 400ms RTT
34
+ latency: 400 * 5
35
+ },
36
+ "Fast 3G": {
37
+ offline: false,
38
+ // ~1.6 Mbps down
39
+ downloadThroughput: 1.6 * 1e3 * 1e3 / 8 * 0.9,
40
+ // ~0.75 Mbps up
41
+ uploadThroughput: 750 * 1e3 / 8 * 0.9,
42
+ // 150ms RTT
43
+ latency: 150 * 3.75
44
+ },
45
+ // alias to Fast 3G to align with Lighthouse (crbug.com/342406608)
46
+ // and DevTools (crbug.com/342406608),
47
+ "Slow 4G": {
48
+ offline: false,
49
+ // ~1.6 Mbps down
50
+ downloadThroughput: 1.6 * 1e3 * 1e3 / 8 * 0.9,
51
+ // ~0.75 Mbps up
52
+ uploadThroughput: 750 * 1e3 / 8 * 0.9,
53
+ // 150ms RTT
54
+ latency: 150 * 3.75
55
+ },
56
+ "Fast 4G": {
57
+ offline: false,
58
+ // 9 Mbps down
59
+ downloadThroughput: 9 * 1e3 * 1e3 / 8 * 0.9,
60
+ // 1.5 Mbps up
61
+ uploadThroughput: 1.5 * 1e3 * 1e3 / 8 * 0.9,
62
+ // 60ms RTT
63
+ latency: 60 * 2.75
64
+ },
65
+ /**
66
+ * Network conditions used for desktop in Lighthouse/PSI.
67
+ *
68
+ * 10,240 kb/s throughput with 40 ms TCP RTT.
69
+ *
70
+ * @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49
71
+ * @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6
72
+ */
73
+ Broadband: {
74
+ offline: false,
75
+ downloadThroughput: 10240 * 1e3 / 8,
76
+ uploadThroughput: 10240 * 1e3 / 8,
77
+ latency: 40
78
+ }
60
79
  };
61
80
  async function emulateNetworkConditions(condition) {
62
- if ('chromium' !== this.browserName) {
63
- throw new Error('CDP sessions are only supported on Chromium-based browsers');
64
- }
65
- const session = await this.page.context().newCDPSession(this.page);
66
- await session.send('Network.emulateNetworkConditions', 'string' === typeof condition
67
- ? PredefinedNetworkConditions[condition]
68
- : condition);
69
- await session.detach();
81
+ if ("chromium" !== this.browserName) {
82
+ throw new Error(
83
+ "CDP sessions are only supported on Chromium-based browsers"
84
+ );
85
+ }
86
+ const session = await this.page.context().newCDPSession(this.page);
87
+ await session.send(
88
+ "Network.emulateNetworkConditions",
89
+ "string" === typeof condition ? PredefinedNetworkConditions[condition] : condition
90
+ );
91
+ await session.detach();
70
92
  }
71
- //# sourceMappingURL=emulate-network-conditions.js.map
93
+ // Annotate the CommonJS export names for ESM import in node:
94
+ 0 && (module.exports = {
95
+ emulateNetworkConditions
96
+ });
97
+ //# sourceMappingURL=emulate-network-conditions.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"emulate-network-conditions.js","sourceRoot":"","sources":["../../src/page-utils/emulate-network-conditions.ts"],"names":[],"mappings":";;AAkFA,4DAkBC;AA5ED,qKAAqK;AACrK,MAAM,2BAA2B,GAAwC;IACxE,kCAAkC;IAClC,sLAAsL;IACtL,SAAS,EAAE;QACV,OAAO,EAAE,KAAK;QACd,gBAAgB;QAChB,kBAAkB,EAAE,CAAE,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BAAkB,EAAE,CAAE,KAAK,GAAG,IAAI,CAAE,GAAG,CAAC;QACxC,gBAAgB,EAAE,CAAE,KAAK,GAAG,IAAI,CAAE,GAAG,CAAC;QACtC,OAAO,EAAE,EAAE;KACX;CACD,CAAC;AAEK,KAAK,UAAU,wBAAwB,CAE7C,SAAuE;IAEvE,IAAK,UAAU,KAAK,IAAI,CAAC,WAAW,EAAG,CAAC;QACvC,MAAM,IAAI,KAAK,CACd,4DAA4D,CAC5D,CAAC;IACH,CAAC;IAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,aAAa,CAAE,IAAI,CAAC,IAAI,CAAE,CAAC;IACrE,MAAM,OAAO,CAAC,IAAI,CACjB,kCAAkC,EAClC,QAAQ,KAAK,OAAO,SAAS;QAC5B,CAAC,CAAC,2BAA2B,CAAE,SAAS,CAAE;QAC1C,CAAC,CAAC,SAAS,CACZ,CAAC;IACF,MAAM,OAAO,CAAC,MAAM,EAAE,CAAC;AACxB,CAAC"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/page-utils/emulate-network-conditions.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type { PageUtils } from './';\n\ninterface NetworkConditions {\n\t/**\n\t * True to emulate internet disconnection.\n\t */\n\toffline: boolean;\n\t/**\n\t * Minimum latency from request sent to response headers received (ms).\n\t */\n\tlatency: number;\n\t/**\n\t * Maximal aggregated download throughput (bytes/sec). -1 disables download throttling.\n\t */\n\tdownloadThroughput: number;\n\t/**\n\t * Maximal aggregated upload throughput (bytes/sec). -1 disables upload throttling.\n\t */\n\tuploadThroughput: number;\n}\n\n// Defaults from https://github.com/puppeteer/puppeteer/blob/401355610874beac23a51dcb75739a4bb4191a2b/packages/puppeteer-core/src/cdp/PredefinedNetworkConditions.ts.\nconst PredefinedNetworkConditions: Record< string, NetworkConditions > = {\n\t// Generally aligned with DevTools\n\t// https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/core/sdk/NetworkManager.ts;l=398;drc=225e1240f522ca684473f541ae6dae6cd766dd33.\n\t'Slow 3G': {\n\t\toffline: false,\n\t\t// ~500Kbps down\n\t\tdownloadThroughput: ( ( 500 * 1000 ) / 8 ) * 0.8,\n\t\t// ~500Kbps up\n\t\tuploadThroughput: ( ( 500 * 1000 ) / 8 ) * 0.8,\n\t\t// 400ms RTT\n\t\tlatency: 400 * 5,\n\t},\n\t'Fast 3G': {\n\t\toffline: false,\n\t\t// ~1.6 Mbps down\n\t\tdownloadThroughput: ( ( 1.6 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// ~0.75 Mbps up\n\t\tuploadThroughput: ( ( 750 * 1000 ) / 8 ) * 0.9,\n\t\t// 150ms RTT\n\t\tlatency: 150 * 3.75,\n\t},\n\t// alias to Fast 3G to align with Lighthouse (crbug.com/342406608)\n\t// and DevTools (crbug.com/342406608),\n\t'Slow 4G': {\n\t\toffline: false,\n\t\t// ~1.6 Mbps down\n\t\tdownloadThroughput: ( ( 1.6 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// ~0.75 Mbps up\n\t\tuploadThroughput: ( ( 750 * 1000 ) / 8 ) * 0.9,\n\t\t// 150ms RTT\n\t\tlatency: 150 * 3.75,\n\t},\n\t'Fast 4G': {\n\t\toffline: false,\n\t\t// 9 Mbps down\n\t\tdownloadThroughput: ( ( 9 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// 1.5 Mbps up\n\t\tuploadThroughput: ( ( 1.5 * 1000 * 1000 ) / 8 ) * 0.9,\n\t\t// 60ms RTT\n\t\tlatency: 60 * 2.75,\n\t},\n\t/**\n\t * Network conditions used for desktop in Lighthouse/PSI.\n\t *\n\t * 10,240 kb/s throughput with 40 ms TCP RTT.\n\t *\n\t * @see https://github.com/paulirish/lighthouse/blob/f0855904aaffaecf3089169449646960782d7e92/core/config/constants.js#L40-L49\n\t * @see https://docs.google.com/document/d/1-p4HSp42REEA5-jCBVB6PqQcVhI1nQIblBCNKhPJUXg/edit?tab=t.0#heading=h.jsap7yf4phk6\n\t */\n\tBroadband: {\n\t\toffline: false,\n\t\tdownloadThroughput: ( 10240 * 1000 ) / 8,\n\t\tuploadThroughput: ( 10240 * 1000 ) / 8,\n\t\tlatency: 40,\n\t},\n};\n\nexport async function emulateNetworkConditions(\n\tthis: PageUtils,\n\tcondition: keyof typeof PredefinedNetworkConditions | NetworkConditions\n) {\n\tif ( 'chromium' !== this.browserName ) {\n\t\tthrow new Error(\n\t\t\t'CDP sessions are only supported on Chromium-based browsers'\n\t\t);\n\t}\n\n\tconst session = await this.page.context().newCDPSession( this.page );\n\tawait session.send(\n\t\t'Network.emulateNetworkConditions',\n\t\t'string' === typeof condition\n\t\t\t? PredefinedNetworkConditions[ condition ]\n\t\t\t: condition\n\t);\n\tawait session.detach();\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBA,MAAM,8BAAmE;AAAA;AAAA;AAAA,EAGxE,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE7C,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAEpD,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA;AAAA;AAAA,EAGA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAEpD,kBAAsB,MAAM,MAAS,IAAM;AAAA;AAAA,IAE3C,SAAS,MAAM;AAAA,EAChB;AAAA,EACA,WAAW;AAAA,IACV,SAAS;AAAA;AAAA,IAET,oBAAwB,IAAI,MAAO,MAAS,IAAM;AAAA;AAAA,IAElD,kBAAsB,MAAM,MAAO,MAAS,IAAM;AAAA;AAAA,IAElD,SAAS,KAAK;AAAA,EACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,WAAW;AAAA,IACV,SAAS;AAAA,IACT,oBAAsB,QAAQ,MAAS;AAAA,IACvC,kBAAoB,QAAQ,MAAS;AAAA,IACrC,SAAS;AAAA,EACV;AACD;AAEA,eAAsB,yBAErB,WACC;AACD,MAAK,eAAe,KAAK,aAAc;AACtC,UAAM,IAAI;AAAA,MACT;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,MAAM,KAAK,KAAK,QAAQ,EAAE,cAAe,KAAK,IAAK;AACnE,QAAM,QAAQ;AAAA,IACb;AAAA,IACA,aAAa,OAAO,YACjB,4BAA6B,SAAU,IACvC;AAAA,EACJ;AACA,QAAM,QAAQ,OAAO;AACtB;",
6
+ "names": []
7
+ }
@@ -1,37 +1,57 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PageUtils = void 0;
4
- /**
5
- * Internal dependencies
6
- */
7
- const drag_files_1 = require("./drag-files");
8
- const is_current_url_1 = require("./is-current-url");
9
- const press_keys_1 = require("./press-keys");
10
- const set_browser_viewport_1 = require("./set-browser-viewport");
11
- const emulate_network_conditions_1 = require("./emulate-network-conditions");
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 page_utils_exports = {};
20
+ __export(page_utils_exports, {
21
+ PageUtils: () => PageUtils
22
+ });
23
+ module.exports = __toCommonJS(page_utils_exports);
24
+ var import_drag_files = require("./drag-files");
25
+ var import_is_current_url = require("./is-current-url");
26
+ var import_press_keys = require("./press-keys");
27
+ var import_set_browser_viewport = require("./set-browser-viewport");
28
+ var import_emulate_network_conditions = require("./emulate-network-conditions");
12
29
  class PageUtils {
13
- browser;
14
- page;
15
- context;
16
- browserName;
17
- constructor({ page, browserName }) {
18
- this.page = page;
19
- this.context = page.context();
20
- this.browser = this.context.browser();
21
- this.browserName = browserName;
22
- }
23
- /** @borrows dragFiles as this.dragFiles */
24
- dragFiles = drag_files_1.dragFiles.bind(this);
25
- /** @borrows isCurrentURL as this.isCurrentURL */
26
- isCurrentURL = is_current_url_1.isCurrentURL.bind(this);
27
- /** @borrows pressKeys as this.pressKeys */
28
- pressKeys = press_keys_1.pressKeys.bind(this);
29
- /** @borrows setBrowserViewport as this.setBrowserViewport */
30
- setBrowserViewport = set_browser_viewport_1.setBrowserViewport.bind(this);
31
- /** @borrows setClipboardData as this.setClipboardData */
32
- setClipboardData = press_keys_1.setClipboardData.bind(this);
33
- /** @borrows emulateNetworkConditions as this.emulateNetworkConditions */
34
- emulateNetworkConditions = emulate_network_conditions_1.emulateNetworkConditions.bind(this);
30
+ browser;
31
+ page;
32
+ context;
33
+ browserName;
34
+ constructor({ page, browserName }) {
35
+ this.page = page;
36
+ this.context = page.context();
37
+ this.browser = this.context.browser();
38
+ this.browserName = browserName;
39
+ }
40
+ /** @borrows dragFiles as this.dragFiles */
41
+ dragFiles = import_drag_files.dragFiles.bind(this);
42
+ /** @borrows isCurrentURL as this.isCurrentURL */
43
+ isCurrentURL = import_is_current_url.isCurrentURL.bind(this);
44
+ /** @borrows pressKeys as this.pressKeys */
45
+ pressKeys = import_press_keys.pressKeys.bind(this);
46
+ /** @borrows setBrowserViewport as this.setBrowserViewport */
47
+ setBrowserViewport = import_set_browser_viewport.setBrowserViewport.bind(this);
48
+ /** @borrows setClipboardData as this.setClipboardData */
49
+ setClipboardData = import_press_keys.setClipboardData.bind(this);
50
+ /** @borrows emulateNetworkConditions as this.emulateNetworkConditions */
51
+ emulateNetworkConditions = import_emulate_network_conditions.emulateNetworkConditions.bind(this);
35
52
  }
36
- exports.PageUtils = PageUtils;
37
- //# sourceMappingURL=index.js.map
53
+ // Annotate the CommonJS export names for ESM import in node:
54
+ 0 && (module.exports = {
55
+ PageUtils
56
+ });
57
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/page-utils/index.ts"],"names":[],"mappings":";;;AAUA;;GAEG;AACH,6CAAyC;AACzC,qDAAgD;AAChD,6CAA2D;AAC3D,iEAA4D;AAC5D,6EAAwE;AAOxE,MAAM,SAAS;IACd,OAAO,CAAU;IACjB,IAAI,CAAO;IACX,OAAO,CAAiB;IACxB,WAAW,CAA2C;IAEtD,YAAa,EAAE,IAAI,EAAE,WAAW,EAA6B;QAC5D,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,EAAE,CAAC;QAC9B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,EAAG,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;IAChC,CAAC;IAED,2CAA2C;IAC3C,SAAS,GAAqB,sBAAS,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACrD,iDAAiD;IACjD,YAAY,GAAwB,6BAAY,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC9D,2CAA2C;IAC3C,SAAS,GAAqB,sBAAS,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACrD,6DAA6D;IAC7D,kBAAkB,GACjB,yCAAkB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IACjC,yDAAyD;IACzD,gBAAgB,GAA4B,6BAAgB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;IAC1E,yEAAyE;IACzE,wBAAwB,GACvB,qDAAwB,CAAC,IAAI,CAAE,IAAI,CAAE,CAAC;CACvC;AAEQ,8BAAS"}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/page-utils/index.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type {\n\tBrowser,\n\tPage,\n\tBrowserContext,\n\tPlaywrightWorkerOptions,\n} from '@playwright/test';\n\n/**\n * Internal dependencies\n */\nimport { dragFiles } from './drag-files';\nimport { isCurrentURL } from './is-current-url';\nimport { setClipboardData, pressKeys } from './press-keys';\nimport { setBrowserViewport } from './set-browser-viewport';\nimport { emulateNetworkConditions } from './emulate-network-conditions';\n\ntype PageUtilConstructorParams = {\n\tpage: Page;\n\tbrowserName: PlaywrightWorkerOptions[ 'browserName' ];\n};\n\nclass PageUtils {\n\tbrowser: Browser;\n\tpage: Page;\n\tcontext: BrowserContext;\n\tbrowserName: PlaywrightWorkerOptions[ 'browserName' ];\n\n\tconstructor( { page, browserName }: PageUtilConstructorParams ) {\n\t\tthis.page = page;\n\t\tthis.context = page.context();\n\t\tthis.browser = this.context.browser()!;\n\t\tthis.browserName = browserName;\n\t}\n\n\t/** @borrows dragFiles as this.dragFiles */\n\tdragFiles: typeof dragFiles = dragFiles.bind( this );\n\t/** @borrows isCurrentURL as this.isCurrentURL */\n\tisCurrentURL: typeof isCurrentURL = isCurrentURL.bind( this );\n\t/** @borrows pressKeys as this.pressKeys */\n\tpressKeys: typeof pressKeys = pressKeys.bind( this );\n\t/** @borrows setBrowserViewport as this.setBrowserViewport */\n\tsetBrowserViewport: typeof setBrowserViewport =\n\t\tsetBrowserViewport.bind( this );\n\t/** @borrows setClipboardData as this.setClipboardData */\n\tsetClipboardData: typeof setClipboardData = setClipboardData.bind( this );\n\t/** @borrows emulateNetworkConditions as this.emulateNetworkConditions */\n\temulateNetworkConditions: typeof emulateNetworkConditions =\n\t\temulateNetworkConditions.bind( this );\n}\n\nexport { PageUtils };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,wBAA0B;AAC1B,4BAA6B;AAC7B,wBAA4C;AAC5C,kCAAmC;AACnC,wCAAyC;AAOzC,MAAM,UAAU;AAAA,EACf;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAa,EAAE,MAAM,YAAY,GAA+B;AAC/D,SAAK,OAAO;AACZ,SAAK,UAAU,KAAK,QAAQ;AAC5B,SAAK,UAAU,KAAK,QAAQ,QAAQ;AACpC,SAAK,cAAc;AAAA,EACpB;AAAA;AAAA,EAGA,YAA8B,4BAAU,KAAM,IAAK;AAAA;AAAA,EAEnD,eAAoC,mCAAa,KAAM,IAAK;AAAA;AAAA,EAE5D,YAA8B,4BAAU,KAAM,IAAK;AAAA;AAAA,EAEnD,qBACC,+CAAmB,KAAM,IAAK;AAAA;AAAA,EAE/B,mBAA4C,mCAAiB,KAAM,IAAK;AAAA;AAAA,EAExE,2BACC,2DAAyB,KAAM,IAAK;AACtC;",
6
+ "names": []
7
+ }