@checkly/playwright-core 1.48.24-maxi → 1.48.25-beta.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/lib/generated/bindingsControllerSource.js +7 -0
  2. package/lib/generated/storageScriptSource.js +7 -0
  3. package/lib/server/har/harRecorder.js +3 -1
  4. package/lib/server/trace/recorder/tracing.js +9 -20
  5. package/lib/utils/fileUtils.js +65 -2
  6. package/lib/vite/{traceViewer/assets/codeMirrorModule-tzBrK1V4.js → recorder/assets/codeMirrorModule-baozm8ur.js} +10 -10
  7. package/lib/vite/recorder/assets/{index-BcaUAUCW.js → index-2ElAIWFB.js} +2 -2
  8. package/lib/vite/recorder/index.html +1 -1
  9. package/lib/vite/traceViewer/assets/{codeMirrorModule-CB-2okZ8.js → codeMirrorModule-DblsdhjA.js} +2096 -2331
  10. package/lib/vite/{recorder/assets/codeMirrorModule-CR6kB851.js → traceViewer/assets/codeMirrorModule-lDjkI8Ax.js} +1 -1
  11. package/lib/vite/traceViewer/assets/{inspectorTab-BHcfR9dD.js → inspectorTab-BPzhNk9r.js} +2 -2
  12. package/lib/vite/traceViewer/assets/inspectorTab-DOc4D3cX.js +17361 -0
  13. package/lib/vite/traceViewer/assets/{defaultSettingsView-CBiB4avC.js → testServerConnection-D-tXL3sj.js} +49 -42
  14. package/lib/vite/traceViewer/assets/{workbench-DZqNXdoV.js → workbench-DLv_q9ji.js} +1 -1
  15. package/lib/vite/traceViewer/assets/workbench-DNolpp3y.js +1473 -0
  16. package/lib/vite/traceViewer/assets/xtermModule-DZP0glxx.js +5982 -0
  17. package/lib/vite/traceViewer/{embedded.DInvAijy.js → embedded.BIubxTi3.js} +1 -1
  18. package/lib/vite/traceViewer/{embedded.gzudoghF.js → embedded.DeCrOtlO.js} +4 -4
  19. package/lib/vite/traceViewer/embedded.html +3 -3
  20. package/lib/vite/traceViewer/{index.DilotR1h.js → index.CM_h9lHr.js} +7 -124
  21. package/lib/vite/traceViewer/{index.Dha3cgqs.js → index.DPD22sZn.js} +1 -1
  22. package/lib/vite/traceViewer/index.html +3 -3
  23. package/lib/vite/traceViewer/{inspectorTab.DnGm18kV.css → inspectorTab.DGJWXOSd.css} +1488 -1521
  24. package/lib/vite/traceViewer/{recorder.C88JDknq.js → recorder.BaRuS6Pc.js} +1 -1
  25. package/lib/vite/traceViewer/{recorder.DVrkq3Um.js → recorder.Fwf59ZKh.js} +3 -3
  26. package/lib/vite/traceViewer/recorder.html +2 -2
  27. package/lib/vite/traceViewer/{uiMode.2tr9k625.js → uiMode.B11wexdJ.js} +1 -1
  28. package/lib/vite/traceViewer/{uiMode.C9_OcpPU.js → uiMode.CYBsUhm_.js} +58 -90
  29. package/lib/vite/traceViewer/{uiMode.c5ORgcrX.css → uiMode.DRmgrHSk.css} +45 -7
  30. package/lib/vite/traceViewer/uiMode.html +3 -3
  31. package/lib/vite/traceViewer/{workbench.xUZSA8PY.css → workbench.BQNDbcQ0.css} +83 -320
  32. package/package.json +1 -1
  33. package/lib/client/clientStackTrace.js +0 -66
  34. package/lib/client/fileUtils.js +0 -33
  35. package/lib/client/platform.js +0 -72
  36. package/lib/client/timeoutSettings.js +0 -66
  37. package/lib/client/webSocket.js +0 -107
  38. package/lib/generated/recorderSource.js +0 -7
  39. package/lib/server/callLog.js +0 -80
  40. package/lib/server/harBackend.js +0 -158
  41. package/lib/server/localUtils.js +0 -204
  42. package/lib/server/recorder/chat.js +0 -178
  43. package/lib/server/recorder/codeGenerator.js +0 -154
  44. package/lib/server/recorder/csharp.js +0 -311
  45. package/lib/server/recorder/java.js +0 -249
  46. package/lib/server/recorder/javascript.js +0 -230
  47. package/lib/server/recorder/jsonl.js +0 -48
  48. package/lib/server/recorder/language.js +0 -45
  49. package/lib/server/recorder/python.js +0 -276
  50. package/lib/server/recorder/recorderActions.js +0 -6
  51. package/lib/server/recorder/utils.js +0 -46
  52. package/lib/server/storageScript.js +0 -161
  53. package/lib/server/timeoutSettings.js +0 -75
  54. package/lib/server/utils/ascii.js +0 -32
  55. package/lib/server/utils/comparators.js +0 -160
  56. package/lib/server/utils/crypto.js +0 -172
  57. package/lib/server/utils/debug.js +0 -39
  58. package/lib/server/utils/debugLogger.js +0 -94
  59. package/lib/server/utils/env.js +0 -54
  60. package/lib/server/utils/eventsHelper.js +0 -39
  61. package/lib/server/utils/expectUtils.js +0 -34
  62. package/lib/server/utils/fileUtils.js +0 -205
  63. package/lib/server/utils/happyEyeballs.js +0 -210
  64. package/lib/server/utils/hostPlatform.js +0 -146
  65. package/lib/server/utils/httpServer.js +0 -234
  66. package/lib/server/utils/image_tools/colorUtils.js +0 -99
  67. package/lib/server/utils/image_tools/compare.js +0 -109
  68. package/lib/server/utils/image_tools/imageChannel.js +0 -71
  69. package/lib/server/utils/image_tools/stats.js +0 -103
  70. package/lib/server/utils/linuxUtils.js +0 -59
  71. package/lib/server/utils/network.js +0 -161
  72. package/lib/server/utils/nodePlatform.js +0 -141
  73. package/lib/server/utils/pipeTransport.js +0 -83
  74. package/lib/server/utils/processLauncher.js +0 -249
  75. package/lib/server/utils/profiler.js +0 -53
  76. package/lib/server/utils/socksProxy.js +0 -571
  77. package/lib/server/utils/spawnAsync.js +0 -46
  78. package/lib/server/utils/task.js +0 -59
  79. package/lib/server/utils/userAgent.js +0 -92
  80. package/lib/server/utils/wsServer.js +0 -129
  81. package/lib/server/utils/zipFile.js +0 -76
  82. package/lib/server/utils/zones.js +0 -55
  83. package/lib/utils/glob.js +0 -84
  84. package/lib/utils/isomorphic/ariaSnapshot.js +0 -393
  85. package/lib/utils/isomorphic/assert.js +0 -26
  86. package/lib/utils/isomorphic/colors.js +0 -66
  87. package/lib/utils/isomorphic/headers.js +0 -53
  88. package/lib/utils/isomorphic/manualPromise.js +0 -108
  89. package/lib/utils/isomorphic/multimap.js +0 -74
  90. package/lib/utils/isomorphic/rtti.js +0 -42
  91. package/lib/utils/isomorphic/semaphore.js +0 -52
  92. package/lib/utils/isomorphic/stackTrace.js +0 -170
  93. package/lib/utils/isomorphic/time.js +0 -26
  94. package/lib/utils/isomorphic/timeoutRunner.js +0 -67
  95. package/lib/utils/isomorphic/types.js +0 -6
  96. package/lib/utils/mimeType.js +0 -30
  97. package/lib/utils.js +0 -448
  98. package/lib/vite/traceViewer/assets/codeMirrorModule-DZoSgqUd.js +0 -24
  99. package/lib/vite/traceViewer/assets/inspectorTab-BuJ3wAX_.js +0 -64
  100. package/lib/vite/traceViewer/assets/inspectorTab-CwgfffWb.js +0 -25143
  101. package/lib/vite/traceViewer/assets/workbench-CWZselvp.js +0 -2470
  102. package/lib/vite/traceViewer/assets/workbench-DdmJ9AJV.js +0 -9
  103. package/lib/vite/traceViewer/assets/xtermModule-Es_gt_u7.js +0 -5994
  104. package/lib/vite/traceViewer/defaultSettingsView.Dp3b_92q.css +0 -41
  105. package/lib/vite/traceViewer/embedded.Dxe2heQk.js +0 -2
  106. package/lib/vite/traceViewer/index.CB297BuW.js +0 -2
  107. package/lib/vite/traceViewer/recorder.DNMfnSiu.js +0 -2
  108. package/lib/vite/traceViewer/uiMode.Cr1tvTWS.js +0 -5
  109. /package/lib/vite/traceViewer/{codeMirrorModule.DuST8d_k.css → codeMirrorModule.Cy8X9Wtw.css} +0 -0
  110. /package/lib/vite/traceViewer/{embedded.BeldSa2G.css → embedded.DjZq4InJ.css} +0 -0
  111. /package/lib/vite/traceViewer/{index.QewjJ85u.css → index.QanXxRUb.css} +0 -0
  112. /package/lib/vite/traceViewer/{recorder.DLgqV9db.css → recorder.DBDpiNOK.css} +0 -0
  113. /package/lib/vite/traceViewer/{xtermModule.EsaqrrTX.css → xtermModule.4oRVGWQ-.css} +0 -0
@@ -1,204 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.addStackToTracingNoReply = addStackToTracingNoReply;
7
- exports.harClose = harClose;
8
- exports.harLookup = harLookup;
9
- exports.harOpen = harOpen;
10
- exports.harUnzip = harUnzip;
11
- exports.traceDiscarded = traceDiscarded;
12
- exports.tracingStarted = tracingStarted;
13
- exports.zip = zip;
14
- var _fs = _interopRequireDefault(require("fs"));
15
- var _os = _interopRequireDefault(require("os"));
16
- var _path = _interopRequireDefault(require("path"));
17
- var _crypto = require("./utils/crypto");
18
- var _harBackend = require("./harBackend");
19
- var _manualPromise = require("../utils/isomorphic/manualPromise");
20
- var _zipFile = require("./utils/zipFile");
21
- var _zipBundle = require("../zipBundle");
22
- var _traceUtils = require("../utils/isomorphic/traceUtils");
23
- var _assert = require("../utils/isomorphic/assert");
24
- var _fileUtils = require("./utils/fileUtils");
25
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
26
- /**
27
- * Copyright (c) Microsoft Corporation.
28
- *
29
- * Licensed under the Apache License, Version 2.0 (the 'License");
30
- * you may not use this file except in compliance with the License.
31
- * You may obtain a copy of the License at
32
- *
33
- * http://www.apache.org/licenses/LICENSE-2.0
34
- *
35
- * Unless required by applicable law or agreed to in writing, software
36
- * distributed under the License is distributed on an "AS IS" BASIS,
37
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
38
- * See the License for the specific language governing permissions and
39
- * limitations under the License.
40
- */
41
-
42
- async function zip(stackSessions, params) {
43
- const promise = new _manualPromise.ManualPromise();
44
- const zipFile = new _zipBundle.yazl.ZipFile();
45
- zipFile.on('error', error => promise.reject(error));
46
- const addFile = (file, name) => {
47
- try {
48
- if (_fs.default.statSync(file).isFile()) zipFile.addFile(file, name);
49
- } catch (e) {}
50
- };
51
- for (const entry of params.entries) addFile(entry.value, entry.name);
52
-
53
- // Add stacks and the sources.
54
- const stackSession = params.stacksId ? stackSessions.get(params.stacksId) : undefined;
55
- if (stackSession !== null && stackSession !== void 0 && stackSession.callStacks.length) {
56
- await stackSession.writer;
57
- if (process.env.PW_LIVE_TRACE_STACKS) {
58
- zipFile.addFile(stackSession.file, 'trace.stacks');
59
- } else {
60
- const buffer = Buffer.from(JSON.stringify((0, _traceUtils.serializeClientSideCallMetadata)(stackSession.callStacks)));
61
- zipFile.addBuffer(buffer, 'trace.stacks');
62
- }
63
- }
64
-
65
- // Collect sources from stacks.
66
- if (params.includeSources) {
67
- const sourceFiles = new Set();
68
- for (const {
69
- stack
70
- } of (stackSession === null || stackSession === void 0 ? void 0 : stackSession.callStacks) || []) {
71
- if (!stack) continue;
72
- for (const {
73
- file
74
- } of stack) sourceFiles.add(file);
75
- }
76
- for (const sourceFile of sourceFiles) addFile(sourceFile, 'resources/src@' + (await (0, _crypto.calculateSha1)(sourceFile)) + '.txt');
77
- }
78
- if (params.mode === 'write') {
79
- // New file, just compress the entries.
80
- await _fs.default.promises.mkdir(_path.default.dirname(params.zipFile), {
81
- recursive: true
82
- });
83
- zipFile.end(undefined, () => {
84
- zipFile.outputStream.pipe(_fs.default.createWriteStream(params.zipFile)).on('close', () => promise.resolve()).on('error', error => promise.reject(error));
85
- });
86
- await promise;
87
- await deleteStackSession(stackSessions, params.stacksId);
88
- return;
89
- }
90
-
91
- // File already exists. Repack and add new entries.
92
- const tempFile = params.zipFile + '.tmp';
93
- await _fs.default.promises.rename(params.zipFile, tempFile);
94
- _zipBundle.yauzl.open(tempFile, (err, inZipFile) => {
95
- if (err) {
96
- promise.reject(err);
97
- return;
98
- }
99
- (0, _assert.assert)(inZipFile);
100
- let pendingEntries = inZipFile.entryCount;
101
- inZipFile.on('entry', entry => {
102
- inZipFile.openReadStream(entry, (err, readStream) => {
103
- if (err) {
104
- promise.reject(err);
105
- return;
106
- }
107
- zipFile.addReadStream(readStream, entry.fileName);
108
- if (--pendingEntries === 0) {
109
- zipFile.end(undefined, () => {
110
- zipFile.outputStream.pipe(_fs.default.createWriteStream(params.zipFile)).on('close', () => {
111
- _fs.default.promises.unlink(tempFile).then(() => {
112
- promise.resolve();
113
- }).catch(error => promise.reject(error));
114
- });
115
- });
116
- }
117
- });
118
- });
119
- });
120
- await promise;
121
- await deleteStackSession(stackSessions, params.stacksId);
122
- }
123
- async function deleteStackSession(stackSessions, stacksId) {
124
- const session = stacksId ? stackSessions.get(stacksId) : undefined;
125
- if (!session) return;
126
- await session.writer;
127
- if (session.tmpDir) await (0, _fileUtils.removeFolders)([session.tmpDir]);
128
- stackSessions.delete(stacksId);
129
- }
130
- async function harOpen(harBackends, params) {
131
- let harBackend;
132
- if (params.file.endsWith('.zip')) {
133
- const zipFile = new _zipFile.ZipFile(params.file);
134
- const entryNames = await zipFile.entries();
135
- const harEntryName = entryNames.find(e => e.endsWith('.har'));
136
- if (!harEntryName) return {
137
- error: 'Specified archive does not have a .har file'
138
- };
139
- const har = await zipFile.read(harEntryName);
140
- const harFile = JSON.parse(har.toString());
141
- harBackend = new _harBackend.HarBackend(harFile, null, zipFile);
142
- } else {
143
- const harFile = JSON.parse(await _fs.default.promises.readFile(params.file, 'utf-8'));
144
- harBackend = new _harBackend.HarBackend(harFile, _path.default.dirname(params.file), null);
145
- }
146
- harBackends.set(harBackend.id, harBackend);
147
- return {
148
- harId: harBackend.id
149
- };
150
- }
151
- async function harLookup(harBackends, params) {
152
- const harBackend = harBackends.get(params.harId);
153
- if (!harBackend) return {
154
- action: 'error',
155
- message: `Internal error: har was not opened`
156
- };
157
- return await harBackend.lookup(params.url, params.method, params.headers, params.postData, params.isNavigationRequest);
158
- }
159
- async function harClose(harBackends, params) {
160
- const harBackend = harBackends.get(params.harId);
161
- if (harBackend) {
162
- harBackends.delete(harBackend.id);
163
- harBackend.dispose();
164
- }
165
- }
166
- async function harUnzip(params) {
167
- const dir = _path.default.dirname(params.zipFile);
168
- const zipFile = new _zipFile.ZipFile(params.zipFile);
169
- for (const entry of await zipFile.entries()) {
170
- const buffer = await zipFile.read(entry);
171
- if (entry === 'har.har') await _fs.default.promises.writeFile(params.harFile, buffer);else await _fs.default.promises.writeFile(_path.default.join(dir, entry), buffer);
172
- }
173
- zipFile.close();
174
- await _fs.default.promises.unlink(params.zipFile);
175
- }
176
- async function tracingStarted(stackSessions, params) {
177
- let tmpDir = undefined;
178
- if (!params.tracesDir) tmpDir = await _fs.default.promises.mkdtemp(_path.default.join(_os.default.tmpdir(), 'playwright-tracing-'));
179
- const traceStacksFile = _path.default.join(params.tracesDir || tmpDir, params.traceName + '.stacks');
180
- stackSessions.set(traceStacksFile, {
181
- callStacks: [],
182
- file: traceStacksFile,
183
- writer: Promise.resolve(),
184
- tmpDir
185
- });
186
- return {
187
- stacksId: traceStacksFile
188
- };
189
- }
190
- async function traceDiscarded(stackSessions, params) {
191
- await deleteStackSession(stackSessions, params.stacksId);
192
- }
193
- async function addStackToTracingNoReply(stackSessions, params) {
194
- for (const session of stackSessions.values()) {
195
- session.callStacks.push(params.callData);
196
- if (process.env.PW_LIVE_TRACE_STACKS) {
197
- session.writer = session.writer.then(() => {
198
- const buffer = Buffer.from(JSON.stringify((0, _traceUtils.serializeClientSideCallMetadata)(session.callStacks)));
199
- return _fs.default.promises.writeFile(session.file, buffer);
200
- });
201
- }
202
- }
203
- }
204
- //# sourceMappingURL=localUtils.js.map
@@ -1,178 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Chat = void 0;
7
- exports.asString = asString;
8
- var _transport = require("../transport");
9
- /**
10
- * Copyright (c) Microsoft Corporation.
11
- *
12
- * Licensed under the Apache License, Version 2.0 (the "License");
13
- * you may not use this file except in compliance with the License.
14
- * You may obtain a copy of the License at
15
- *
16
- * http://www.apache.org/licenses/LICENSE-2.0
17
- *
18
- * Unless required by applicable law or agreed to in writing, software
19
- * distributed under the License is distributed on an "AS IS" BASIS,
20
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
- * See the License for the specific language governing permissions and
22
- * limitations under the License.
23
- */
24
-
25
- class Chat {
26
- constructor(wsEndpoint) {
27
- this._history = [];
28
- this._connectionPromise = void 0;
29
- this._chatSinks = new Map();
30
- this._wsEndpoint = void 0;
31
- this._wsEndpoint = wsEndpoint;
32
- }
33
- clearHistory() {
34
- this._history = [];
35
- }
36
- async post(prompt) {
37
- await this._append('user', prompt);
38
- let text = await asString(await this._post());
39
- if (text.startsWith('```json') && text.endsWith('```')) text = text.substring('```json'.length, text.length - '```'.length);
40
- for (let i = 0; i < 3; ++i) {
41
- try {
42
- return JSON.parse(text);
43
- } catch (e) {
44
- await this._append('user', String(e));
45
- }
46
- }
47
- throw new Error('Failed to parse response: ' + text);
48
- }
49
- async _append(user, content) {
50
- this._history.push({
51
- user,
52
- content
53
- });
54
- }
55
- async _connection() {
56
- if (!this._connectionPromise) {
57
- this._connectionPromise = _transport.WebSocketTransport.connect(undefined, this._wsEndpoint).then(transport => {
58
- return new Connection(transport, (method, params) => this._dispatchEvent(method, params), () => {});
59
- });
60
- }
61
- return this._connectionPromise;
62
- }
63
- _dispatchEvent(method, params) {
64
- if (method === 'chatChunk') {
65
- const {
66
- chatId,
67
- chunk
68
- } = params;
69
- const chunkSink = this._chatSinks.get(chatId);
70
- chunkSink(chunk);
71
- if (!chunk) this._chatSinks.delete(chatId);
72
- }
73
- }
74
- async _post() {
75
- const connection = await this._connection();
76
- const result = await connection.send('chat', {
77
- history: this._history
78
- });
79
- const {
80
- chatId
81
- } = result;
82
- const {
83
- iterable,
84
- addChunk
85
- } = iterablePump();
86
- this._chatSinks.set(chatId, addChunk);
87
- return iterable;
88
- }
89
- }
90
- exports.Chat = Chat;
91
- async function asString(stream) {
92
- let result = '';
93
- for await (const chunk of stream) result += chunk;
94
- return result;
95
- }
96
- function iterablePump() {
97
- let controller;
98
- const stream = new ReadableStream({
99
- start: c => controller = c
100
- });
101
- const iterable = async function* () {
102
- const reader = stream.getReader();
103
- while (true) {
104
- const {
105
- done,
106
- value
107
- } = await reader.read();
108
- if (done) break;
109
- yield value;
110
- }
111
- }();
112
- return {
113
- iterable,
114
- addChunk: chunk => {
115
- if (chunk) controller.enqueue(chunk);else controller.close();
116
- }
117
- };
118
- }
119
- class Connection {
120
- constructor(transport, onEvent, onClose) {
121
- this._transport = void 0;
122
- this._lastId = 0;
123
- this._closed = false;
124
- this._pending = new Map();
125
- this._onEvent = void 0;
126
- this._onClose = void 0;
127
- this._transport = transport;
128
- this._onEvent = onEvent;
129
- this._onClose = onClose;
130
- this._transport.onmessage = this._dispatchMessage.bind(this);
131
- this._transport.onclose = this._close.bind(this);
132
- }
133
- send(method, params) {
134
- const id = this._lastId++;
135
- const message = {
136
- id,
137
- method,
138
- params
139
- };
140
- this._transport.send(message);
141
- return new Promise((resolve, reject) => {
142
- this._pending.set(id, {
143
- resolve,
144
- reject
145
- });
146
- });
147
- }
148
- _dispatchMessage(message) {
149
- if (message.id === undefined) {
150
- this._onEvent(message.method, message.params);
151
- return;
152
- }
153
- const callback = this._pending.get(message.id);
154
- this._pending.delete(message.id);
155
- if (!callback) return;
156
- if (message.error) {
157
- callback.reject(new Error(message.error.message));
158
- return;
159
- }
160
- callback.resolve(message.result);
161
- }
162
- _close() {
163
- this._closed = true;
164
- this._transport.onmessage = undefined;
165
- this._transport.onclose = undefined;
166
- for (const {
167
- reject
168
- } of this._pending.values()) reject(new Error('Connection closed'));
169
- this._onClose();
170
- }
171
- isClosed() {
172
- return this._closed;
173
- }
174
- close() {
175
- if (!this._closed) this._transport.close();
176
- }
177
- }
178
- //# sourceMappingURL=chat.js.map
@@ -1,154 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.CodeGenerator = void 0;
7
- var _events = require("events");
8
- /**
9
- * Copyright (c) Microsoft Corporation.
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- class CodeGenerator extends _events.EventEmitter {
25
- constructor(browserName, enabled, launchOptions, contextOptions, deviceName, saveStorage) {
26
- super();
27
-
28
- // Make a copy of options to modify them later.
29
- this._currentAction = null;
30
- this._lastAction = null;
31
- this._actions = [];
32
- this._enabled = void 0;
33
- this._options = void 0;
34
- launchOptions = {
35
- headless: false,
36
- ...launchOptions
37
- };
38
- contextOptions = {
39
- ...contextOptions
40
- };
41
- this._enabled = enabled;
42
- this._options = {
43
- browserName,
44
- launchOptions,
45
- contextOptions,
46
- deviceName,
47
- saveStorage
48
- };
49
- this.restart();
50
- }
51
- restart() {
52
- this._currentAction = null;
53
- this._lastAction = null;
54
- this._actions = [];
55
- this.emit('change');
56
- }
57
- setEnabled(enabled) {
58
- this._enabled = enabled;
59
- }
60
- addAction(action) {
61
- if (!this._enabled) return;
62
- this.willPerformAction(action);
63
- this.didPerformAction(action);
64
- }
65
- willPerformAction(action) {
66
- if (!this._enabled) return;
67
- this._currentAction = action;
68
- }
69
- performedActionFailed(action) {
70
- if (!this._enabled) return;
71
- if (this._currentAction === action) this._currentAction = null;
72
- }
73
- didPerformAction(actionInContext) {
74
- if (!this._enabled) return;
75
- const action = actionInContext.action;
76
- let eraseLastAction = false;
77
- if (this._lastAction && this._lastAction.frame.pageAlias === actionInContext.frame.pageAlias) {
78
- const lastAction = this._lastAction.action;
79
- // We augment last action based on the type.
80
- if (this._lastAction && action.name === 'fill' && lastAction.name === 'fill') {
81
- if (action.selector === lastAction.selector) eraseLastAction = true;
82
- }
83
- if (lastAction && action.name === 'click' && lastAction.name === 'click') {
84
- if (action.selector === lastAction.selector && action.clickCount > lastAction.clickCount) eraseLastAction = true;
85
- }
86
- if (lastAction && action.name === 'navigate' && lastAction.name === 'navigate') {
87
- if (action.url === lastAction.url) {
88
- // Already at a target URL.
89
- this._currentAction = null;
90
- return;
91
- }
92
- }
93
- // Check and uncheck erase click.
94
- if (lastAction && (action.name === 'check' || action.name === 'uncheck') && lastAction.name === 'click') {
95
- if (action.selector === lastAction.selector) eraseLastAction = true;
96
- }
97
- }
98
- this._lastAction = actionInContext;
99
- this._currentAction = null;
100
- if (eraseLastAction) this._actions.pop();
101
- this._actions.push(actionInContext);
102
- this.emit('change');
103
- }
104
- commitLastAction() {
105
- if (!this._enabled) return;
106
- const action = this._lastAction;
107
- if (action) action.committed = true;
108
- }
109
- signal(pageAlias, frame, signal) {
110
- if (!this._enabled) return;
111
-
112
- // Signal either arrives while action is being performed or shortly after.
113
- if (this._currentAction) {
114
- this._currentAction.action.signals.push(signal);
115
- return;
116
- }
117
- if (this._lastAction && !this._lastAction.committed) {
118
- const signals = this._lastAction.action.signals;
119
- if (signal.name === 'navigation' && signals.length && signals[signals.length - 1].name === 'download') return;
120
- if (signal.name === 'download' && signals.length && signals[signals.length - 1].name === 'navigation') signals.length = signals.length - 1;
121
- this._lastAction.action.signals.push(signal);
122
- this.emit('change');
123
- return;
124
- }
125
- if (signal.name === 'navigation' && frame._page.mainFrame() === frame) {
126
- this.addAction({
127
- frame: {
128
- pageAlias,
129
- isMainFrame: true
130
- },
131
- committed: true,
132
- action: {
133
- name: 'navigate',
134
- url: frame.url(),
135
- signals: []
136
- }
137
- });
138
- }
139
- }
140
- generateStructure(languageGenerator) {
141
- const header = languageGenerator.generateHeader(this._options);
142
- const footer = languageGenerator.generateFooter(this._options.saveStorage);
143
- const actions = this._actions.map(a => languageGenerator.generateAction(a)).filter(Boolean);
144
- const text = [header, ...actions, footer].join('\n');
145
- return {
146
- header,
147
- footer,
148
- actions,
149
- text
150
- };
151
- }
152
- }
153
- exports.CodeGenerator = CodeGenerator;
154
- //# sourceMappingURL=codeGenerator.js.map