@checkly/playwright-core 1.51.16 → 1.51.17-beta.1

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 (86) hide show
  1. package/lib/checkly/secretsFilter.js +10 -5
  2. package/lib/common/socksProxy.js +569 -0
  3. package/lib/common/timeoutSettings.js +73 -0
  4. package/lib/common/types.js +5 -0
  5. package/lib/image_tools/colorUtils.js +98 -0
  6. package/lib/image_tools/compare.js +108 -0
  7. package/lib/image_tools/imageChannel.js +70 -0
  8. package/lib/image_tools/stats.js +102 -0
  9. package/lib/protocol/transport.js +82 -0
  10. package/lib/third_party/diff_match_patch.js +2222 -0
  11. package/lib/utils/ascii.js +31 -0
  12. package/lib/utils/comparators.js +171 -0
  13. package/lib/utils/crypto.js +174 -0
  14. package/lib/utils/debug.js +46 -0
  15. package/lib/utils/debugLogger.js +91 -0
  16. package/lib/utils/env.js +49 -0
  17. package/lib/utils/eventsHelper.js +38 -0
  18. package/lib/utils/happy-eyeballs.js +210 -0
  19. package/lib/utils/headers.js +52 -0
  20. package/lib/utils/hostPlatform.js +133 -0
  21. package/lib/utils/httpServer.js +237 -0
  22. package/lib/utils/linuxUtils.js +78 -0
  23. package/lib/utils/manualPromise.js +109 -0
  24. package/lib/utils/multimap.js +75 -0
  25. package/lib/utils/network.js +160 -0
  26. package/lib/utils/processLauncher.js +248 -0
  27. package/lib/utils/profiler.js +53 -0
  28. package/lib/utils/rtti.js +44 -0
  29. package/lib/utils/semaphore.js +51 -0
  30. package/lib/utils/spawnAsync.js +45 -0
  31. package/lib/utils/task.js +58 -0
  32. package/lib/utils/time.js +37 -0
  33. package/lib/utils/traceUtils.js +44 -0
  34. package/lib/utils/userAgent.js +105 -0
  35. package/lib/utils/wsServer.js +127 -0
  36. package/lib/utils/zipFile.js +75 -0
  37. package/lib/vite/recorder/assets/codeMirrorModule-DrMbgOIo.js +16684 -0
  38. package/lib/vite/recorder/assets/codeMirrorModule-DuST8d_k.css +344 -0
  39. package/lib/vite/recorder/assets/index-5NM3V7eb.css +2524 -0
  40. package/lib/vite/recorder/assets/index-CT-scFHn.js +16848 -0
  41. package/lib/vite/recorder/index.html +2 -2
  42. package/lib/vite/traceViewer/assets/codeMirrorModule-CB-2okZ8.js +16684 -0
  43. package/lib/vite/traceViewer/assets/defaultSettingsView-CBiB4avC.js +217 -0
  44. package/lib/vite/traceViewer/assets/inspectorTab-CwgfffWb.js +25143 -0
  45. package/lib/vite/traceViewer/assets/workbench-CWZselvp.js +2470 -0
  46. package/lib/vite/traceViewer/assets/xtermModule-Es_gt_u7.js +5994 -0
  47. package/lib/vite/traceViewer/codeMirrorModule.DuST8d_k.css +344 -0
  48. package/lib/vite/traceViewer/defaultSettingsView.Dp3b_92q.css +41 -0
  49. package/lib/vite/traceViewer/embedded.BeldSa2G.css +68 -0
  50. package/lib/vite/traceViewer/embedded.gzudoghF.js +106 -0
  51. package/lib/vite/traceViewer/embedded.html +6 -6
  52. package/lib/vite/traceViewer/index.DilotR1h.js +314 -0
  53. package/lib/vite/traceViewer/index.QewjJ85u.css +131 -0
  54. package/lib/vite/traceViewer/index.html +8 -8
  55. package/lib/vite/traceViewer/inspectorTab.DnGm18kV.css +3178 -0
  56. package/lib/vite/traceViewer/recorder.DLgqV9db.css +15 -0
  57. package/lib/vite/traceViewer/recorder.DVrkq3Um.js +551 -0
  58. package/lib/vite/traceViewer/recorder.html +4 -4
  59. package/lib/vite/traceViewer/uiMode.C9_OcpPU.js +1756 -0
  60. package/lib/vite/traceViewer/uiMode.c5ORgcrX.css +1424 -0
  61. package/lib/vite/traceViewer/uiMode.html +8 -8
  62. package/lib/vite/traceViewer/workbench.xUZSA8PY.css +787 -0
  63. package/lib/vite/traceViewer/xtermModule.EsaqrrTX.css +209 -0
  64. package/package.json +1 -1
  65. package/lib/vite/recorder/assets/codeMirrorModule-B9YMkrwa.js +0 -24
  66. package/lib/vite/recorder/assets/codeMirrorModule-C3UTv-Ge.css +0 -1
  67. package/lib/vite/recorder/assets/index-ELPgmkwA.js +0 -184
  68. package/lib/vite/recorder/assets/index-eHBmevrY.css +0 -1
  69. package/lib/vite/traceViewer/assets/codeMirrorModule-gU1OOCQO.js +0 -24
  70. package/lib/vite/traceViewer/assets/defaultSettingsView-B5n_FjMx.js +0 -1
  71. package/lib/vite/traceViewer/assets/inspectorTab-6Tru8Mn_.js +0 -235
  72. package/lib/vite/traceViewer/assets/workbench-B_Nj4NA2.js +0 -25
  73. package/lib/vite/traceViewer/assets/xtermModule-BoAIEibi.js +0 -9
  74. package/lib/vite/traceViewer/codeMirrorModule.C3UTv-Ge.css +0 -1
  75. package/lib/vite/traceViewer/defaultSettingsView.CO3FR0CX.css +0 -1
  76. package/lib/vite/traceViewer/embedded.DpNPH6mk.js +0 -2
  77. package/lib/vite/traceViewer/embedded.mLhjB5IF.css +0 -1
  78. package/lib/vite/traceViewer/index.CFOW-Ezb.css +0 -1
  79. package/lib/vite/traceViewer/index.CuE3SYGw.js +0 -2
  80. package/lib/vite/traceViewer/inspectorTab.CXDulcFG.css +0 -1
  81. package/lib/vite/traceViewer/recorder.BD-uZJs7.js +0 -2
  82. package/lib/vite/traceViewer/recorder.tn0RQdqM.css +0 -0
  83. package/lib/vite/traceViewer/uiMode.BatfzHMG.css +0 -1
  84. package/lib/vite/traceViewer/uiMode.DHrNgddz.js +0 -5
  85. package/lib/vite/traceViewer/workbench.B9vIAzH9.css +0 -1
  86. package/lib/vite/traceViewer/xtermModule.Beg8tuEN.css +0 -32
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.jsonStringifyForceASCII = jsonStringifyForceASCII;
7
+ exports.wrapInASCIIBox = wrapInASCIIBox;
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
+ function wrapInASCIIBox(text, padding = 0) {
25
+ const lines = text.split('\n');
26
+ const maxLength = Math.max(...lines.map(line => line.length));
27
+ return ['╔' + '═'.repeat(maxLength + padding * 2) + '╗', ...lines.map(line => '║' + ' '.repeat(padding) + line + ' '.repeat(maxLength - line.length + padding) + '║'), '╚' + '═'.repeat(maxLength + padding * 2) + '╝'].join('\n');
28
+ }
29
+ function jsonStringifyForceASCII(object) {
30
+ return JSON.stringify(object).replace(/[\u007f-\uffff]/g, c => '\\u' + ('0000' + c.charCodeAt(0).toString(16)).slice(-4));
31
+ }
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getComparator = getComparator;
7
+ var _utilsBundle = require("../utilsBundle");
8
+ var _compare = require("../image_tools/compare");
9
+ /**
10
+ * Copyright 2017 Google Inc. All rights reserved.
11
+ * Modifications copyright (c) Microsoft Corporation.
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+
26
+ const pixelmatch = require('../third_party/pixelmatch');
27
+ const {
28
+ diff_match_patch,
29
+ DIFF_INSERT,
30
+ DIFF_DELETE,
31
+ DIFF_EQUAL
32
+ } = require('../third_party/diff_match_patch');
33
+ function getComparator(mimeType) {
34
+ if (mimeType === 'image/png') return compareImages.bind(null, 'image/png');
35
+ if (mimeType === 'image/jpeg') return compareImages.bind(null, 'image/jpeg');
36
+ if (mimeType === 'text/plain') return compareText;
37
+ return compareBuffersOrStrings;
38
+ }
39
+ const JPEG_JS_MAX_BUFFER_SIZE_IN_MB = 5 * 1024; // ~5 GB
40
+
41
+ function compareBuffersOrStrings(actualBuffer, expectedBuffer) {
42
+ if (typeof actualBuffer === 'string') return compareText(actualBuffer, expectedBuffer);
43
+ if (!actualBuffer || !(actualBuffer instanceof Buffer)) return {
44
+ errorMessage: 'Actual result should be a Buffer or a string.'
45
+ };
46
+ if (Buffer.compare(actualBuffer, expectedBuffer)) return {
47
+ errorMessage: 'Buffers differ'
48
+ };
49
+ return null;
50
+ }
51
+ function compareImages(mimeType, actualBuffer, expectedBuffer, options = {}) {
52
+ var _options$comparator, _ref;
53
+ if (!actualBuffer || !(actualBuffer instanceof Buffer)) return {
54
+ errorMessage: 'Actual result should be a Buffer.'
55
+ };
56
+ validateBuffer(expectedBuffer, mimeType);
57
+ let actual = mimeType === 'image/png' ? _utilsBundle.PNG.sync.read(actualBuffer) : _utilsBundle.jpegjs.decode(actualBuffer, {
58
+ maxMemoryUsageInMB: JPEG_JS_MAX_BUFFER_SIZE_IN_MB
59
+ });
60
+ let expected = mimeType === 'image/png' ? _utilsBundle.PNG.sync.read(expectedBuffer) : _utilsBundle.jpegjs.decode(expectedBuffer, {
61
+ maxMemoryUsageInMB: JPEG_JS_MAX_BUFFER_SIZE_IN_MB
62
+ });
63
+ const size = {
64
+ width: Math.max(expected.width, actual.width),
65
+ height: Math.max(expected.height, actual.height)
66
+ };
67
+ let sizesMismatchError = '';
68
+ if (expected.width !== actual.width || expected.height !== actual.height) {
69
+ sizesMismatchError = `Expected an image ${expected.width}px by ${expected.height}px, received ${actual.width}px by ${actual.height}px. `;
70
+ actual = resizeImage(actual, size);
71
+ expected = resizeImage(expected, size);
72
+ }
73
+ const diff = new _utilsBundle.PNG({
74
+ width: size.width,
75
+ height: size.height
76
+ });
77
+ let count;
78
+ if (options.comparator === 'ssim-cie94') {
79
+ count = (0, _compare.compare)(expected.data, actual.data, diff.data, size.width, size.height, {
80
+ // All ΔE* formulae are originally designed to have the difference of 1.0 stand for a "just noticeable difference" (JND).
81
+ // See https://en.wikipedia.org/wiki/Color_difference#CIELAB_%CE%94E*
82
+ maxColorDeltaE94: 1.0
83
+ });
84
+ } else if (((_options$comparator = options.comparator) !== null && _options$comparator !== void 0 ? _options$comparator : 'pixelmatch') === 'pixelmatch') {
85
+ var _options$threshold;
86
+ count = pixelmatch(expected.data, actual.data, diff.data, size.width, size.height, {
87
+ threshold: (_options$threshold = options.threshold) !== null && _options$threshold !== void 0 ? _options$threshold : 0.2
88
+ });
89
+ } else {
90
+ throw new Error(`Configuration specifies unknown comparator "${options.comparator}"`);
91
+ }
92
+ const maxDiffPixels1 = options.maxDiffPixels;
93
+ const maxDiffPixels2 = options.maxDiffPixelRatio !== undefined ? expected.width * expected.height * options.maxDiffPixelRatio : undefined;
94
+ let maxDiffPixels;
95
+ if (maxDiffPixels1 !== undefined && maxDiffPixels2 !== undefined) maxDiffPixels = Math.min(maxDiffPixels1, maxDiffPixels2);else maxDiffPixels = (_ref = maxDiffPixels1 !== null && maxDiffPixels1 !== void 0 ? maxDiffPixels1 : maxDiffPixels2) !== null && _ref !== void 0 ? _ref : 0;
96
+ const ratio = Math.ceil(count / (expected.width * expected.height) * 100) / 100;
97
+ const pixelsMismatchError = count > maxDiffPixels ? `${count} pixels (ratio ${ratio.toFixed(2)} of all image pixels) are different.` : '';
98
+ if (pixelsMismatchError || sizesMismatchError) return {
99
+ errorMessage: sizesMismatchError + pixelsMismatchError,
100
+ diff: _utilsBundle.PNG.sync.write(diff)
101
+ };
102
+ return null;
103
+ }
104
+ function validateBuffer(buffer, mimeType) {
105
+ if (mimeType === 'image/png') {
106
+ const pngMagicNumber = [137, 80, 78, 71, 13, 10, 26, 10];
107
+ if (buffer.length < pngMagicNumber.length || !pngMagicNumber.every((byte, index) => buffer[index] === byte)) throw new Error('could not decode image as PNG.');
108
+ } else if (mimeType === 'image/jpeg') {
109
+ const jpegMagicNumber = [255, 216];
110
+ if (buffer.length < jpegMagicNumber.length || !jpegMagicNumber.every((byte, index) => buffer[index] === byte)) throw new Error('could not decode image as JPEG.');
111
+ }
112
+ }
113
+ function compareText(actual, expectedBuffer) {
114
+ if (typeof actual !== 'string') return {
115
+ errorMessage: 'Actual result should be a string'
116
+ };
117
+ const expected = expectedBuffer.toString('utf-8');
118
+ if (expected === actual) return null;
119
+ const dmp = new diff_match_patch();
120
+ const d = dmp.diff_main(expected, actual);
121
+ dmp.diff_cleanupSemantic(d);
122
+ return {
123
+ errorMessage: diff_prettyTerminal(d)
124
+ };
125
+ }
126
+ function diff_prettyTerminal(diffs) {
127
+ const html = [];
128
+ for (let x = 0; x < diffs.length; x++) {
129
+ const op = diffs[x][0]; // Operation (insert, delete, equal)
130
+ const data = diffs[x][1]; // Text of change.
131
+ const text = data;
132
+ switch (op) {
133
+ case DIFF_INSERT:
134
+ html[x] = _utilsBundle.colors.green(text);
135
+ break;
136
+ case DIFF_DELETE:
137
+ html[x] = _utilsBundle.colors.reset(_utilsBundle.colors.strikethrough(_utilsBundle.colors.red(text)));
138
+ break;
139
+ case DIFF_EQUAL:
140
+ html[x] = text;
141
+ break;
142
+ }
143
+ }
144
+ return html.join('');
145
+ }
146
+ function resizeImage(image, size) {
147
+ if (image.width === size.width && image.height === size.height) return image;
148
+ const buffer = new Uint8Array(size.width * size.height * 4);
149
+ for (let y = 0; y < size.height; y++) {
150
+ for (let x = 0; x < size.width; x++) {
151
+ const to = (y * size.width + x) * 4;
152
+ if (y < image.height && x < image.width) {
153
+ const from = (y * image.width + x) * 4;
154
+ buffer[to] = image.data[from];
155
+ buffer[to + 1] = image.data[from + 1];
156
+ buffer[to + 2] = image.data[from + 2];
157
+ buffer[to + 3] = image.data[from + 3];
158
+ } else {
159
+ buffer[to] = 0;
160
+ buffer[to + 1] = 0;
161
+ buffer[to + 2] = 0;
162
+ buffer[to + 3] = 0;
163
+ }
164
+ }
165
+ }
166
+ return {
167
+ data: Buffer.from(buffer),
168
+ width: size.width,
169
+ height: size.height
170
+ };
171
+ }
@@ -0,0 +1,174 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.calculateSha1 = calculateSha1;
7
+ exports.createGuid = createGuid;
8
+ exports.generateSelfSignedCertificate = generateSelfSignedCertificate;
9
+ var _crypto = _interopRequireDefault(require("crypto"));
10
+ var _debug = require("./debug");
11
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
+ /**
13
+ * Copyright (c) Microsoft Corporation.
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ function createGuid() {
29
+ return _crypto.default.randomBytes(16).toString('hex');
30
+ }
31
+ function calculateSha1(buffer) {
32
+ const hash = _crypto.default.createHash('sha1');
33
+ hash.update(buffer);
34
+ return hash.digest('hex');
35
+ }
36
+
37
+ // Variable-length quantity encoding aka. base-128 encoding
38
+ function encodeBase128(value) {
39
+ const bytes = [];
40
+ do {
41
+ let byte = value & 0x7f;
42
+ value >>>= 7;
43
+ if (bytes.length > 0) byte |= 0x80;
44
+ bytes.push(byte);
45
+ } while (value > 0);
46
+ return Buffer.from(bytes.reverse());
47
+ }
48
+ ;
49
+
50
+ // ASN1/DER Speficiation: https://www.itu.int/rec/T-REC-X.680-X.693-202102-I/en
51
+ class DER {
52
+ static encodeSequence(data) {
53
+ return this._encode(0x30, Buffer.concat(data));
54
+ }
55
+ static encodeInteger(data) {
56
+ (0, _debug.assert)(data >= -128 && data <= 127);
57
+ return this._encode(0x02, Buffer.from([data]));
58
+ }
59
+ static encodeObjectIdentifier(oid) {
60
+ const parts = oid.split('.').map(v => Number(v));
61
+ // Encode the second part, which could be large, using base-128 encoding if necessary
62
+ const output = [encodeBase128(40 * parts[0] + parts[1])];
63
+ for (let i = 2; i < parts.length; i++) {
64
+ output.push(encodeBase128(parts[i]));
65
+ }
66
+ return this._encode(0x06, Buffer.concat(output));
67
+ }
68
+ static encodeNull() {
69
+ return Buffer.from([0x05, 0x00]);
70
+ }
71
+ static encodeSet(data) {
72
+ (0, _debug.assert)(data.length === 1, 'Only one item in the set is supported. We\'d need to sort the data to support more.');
73
+ // We expect the data to be already sorted.
74
+ return this._encode(0x31, Buffer.concat(data));
75
+ }
76
+ static encodeExplicitContextDependent(tag, data) {
77
+ return this._encode(0xa0 + tag, data);
78
+ }
79
+ static encodePrintableString(data) {
80
+ return this._encode(0x13, Buffer.from(data));
81
+ }
82
+ static encodeBitString(data) {
83
+ // The first byte of the content is the number of unused bits at the end
84
+ const unusedBits = 0; // Assuming all bits are used
85
+ const content = Buffer.concat([Buffer.from([unusedBits]), data]);
86
+ return this._encode(0x03, content);
87
+ }
88
+ static encodeDate(date) {
89
+ const year = date.getUTCFullYear();
90
+ const isGeneralizedTime = year >= 2050;
91
+ const parts = [isGeneralizedTime ? year.toString() : year.toString().slice(-2), (date.getUTCMonth() + 1).toString().padStart(2, '0'), date.getUTCDate().toString().padStart(2, '0'), date.getUTCHours().toString().padStart(2, '0'), date.getUTCMinutes().toString().padStart(2, '0'), date.getUTCSeconds().toString().padStart(2, '0')];
92
+ const encodedDate = parts.join('') + 'Z';
93
+ const tag = isGeneralizedTime ? 0x18 : 0x17; // 0x18 for GeneralizedTime, 0x17 for UTCTime
94
+ return this._encode(tag, Buffer.from(encodedDate));
95
+ }
96
+ static _encode(tag, data) {
97
+ const lengthBytes = this._encodeLength(data.length);
98
+ return Buffer.concat([Buffer.from([tag]), lengthBytes, data]);
99
+ }
100
+ static _encodeLength(length) {
101
+ if (length < 128) {
102
+ return Buffer.from([length]);
103
+ } else {
104
+ const lengthBytes = [];
105
+ while (length > 0) {
106
+ lengthBytes.unshift(length & 0xFF);
107
+ length >>= 8;
108
+ }
109
+ return Buffer.from([0x80 | lengthBytes.length, ...lengthBytes]);
110
+ }
111
+ }
112
+ }
113
+
114
+ // X.509 Specification: https://datatracker.ietf.org/doc/html/rfc2459#section-4.1
115
+ function generateSelfSignedCertificate() {
116
+ const {
117
+ privateKey,
118
+ publicKey
119
+ } = _crypto.default.generateKeyPairSync('rsa', {
120
+ modulusLength: 2048
121
+ });
122
+ const publicKeyDer = publicKey.export({
123
+ type: 'pkcs1',
124
+ format: 'der'
125
+ });
126
+ const oneYearInMilliseconds = 365 * 24 * 60 * 60 * 1_000;
127
+ const notBefore = new Date(new Date().getTime() - oneYearInMilliseconds);
128
+ const notAfter = new Date(new Date().getTime() + oneYearInMilliseconds);
129
+
130
+ // List of fields / structure: https://datatracker.ietf.org/doc/html/rfc2459#section-4.1
131
+ const tbsCertificate = DER.encodeSequence([DER.encodeExplicitContextDependent(0, DER.encodeInteger(1)),
132
+ // version
133
+ DER.encodeInteger(1),
134
+ // serialNumber
135
+ DER.encodeSequence([DER.encodeObjectIdentifier('1.2.840.113549.1.1.11'),
136
+ // sha256WithRSAEncryption PKCS #1
137
+ DER.encodeNull()]),
138
+ // signature
139
+ DER.encodeSequence([DER.encodeSet([DER.encodeSequence([DER.encodeObjectIdentifier('2.5.4.3'),
140
+ // commonName X.520 DN component
141
+ DER.encodePrintableString('localhost')])]), DER.encodeSet([DER.encodeSequence([DER.encodeObjectIdentifier('2.5.4.10'),
142
+ // organizationName X.520 DN component
143
+ DER.encodePrintableString('Playwright Client Certificate Support')])])]),
144
+ // issuer
145
+ DER.encodeSequence([DER.encodeDate(notBefore),
146
+ // notBefore
147
+ DER.encodeDate(notAfter) // notAfter
148
+ ]),
149
+ // validity
150
+ DER.encodeSequence([DER.encodeSet([DER.encodeSequence([DER.encodeObjectIdentifier('2.5.4.3'),
151
+ // commonName X.520 DN component
152
+ DER.encodePrintableString('localhost')])]), DER.encodeSet([DER.encodeSequence([DER.encodeObjectIdentifier('2.5.4.10'),
153
+ // organizationName X.520 DN component
154
+ DER.encodePrintableString('Playwright Client Certificate Support')])])]),
155
+ // subject
156
+ DER.encodeSequence([DER.encodeSequence([DER.encodeObjectIdentifier('1.2.840.113549.1.1.1'),
157
+ // rsaEncryption PKCS #1
158
+ DER.encodeNull()]), DER.encodeBitString(publicKeyDer)]) // SubjectPublicKeyInfo
159
+ ]);
160
+ const signature = _crypto.default.sign('sha256', tbsCertificate, privateKey);
161
+ const certificate = DER.encodeSequence([tbsCertificate, DER.encodeSequence([DER.encodeObjectIdentifier('1.2.840.113549.1.1.11'),
162
+ // sha256WithRSAEncryption PKCS #1
163
+ DER.encodeNull()]), DER.encodeBitString(signature)]);
164
+ const certPem = ['-----BEGIN CERTIFICATE-----',
165
+ // Split the base64 string into lines of 64 characters
166
+ certificate.toString('base64').match(/.{1,64}/g).join('\n'), '-----END CERTIFICATE-----'].join('\n');
167
+ return {
168
+ cert: certPem,
169
+ key: privateKey.export({
170
+ type: 'pkcs1',
171
+ format: 'pem'
172
+ })
173
+ };
174
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.assert = assert;
7
+ exports.debugAssert = debugAssert;
8
+ exports.debugMode = debugMode;
9
+ exports.isUnderTest = isUnderTest;
10
+ exports.setUnderTest = setUnderTest;
11
+ var _env = require("./env");
12
+ /**
13
+ * Copyright (c) Microsoft Corporation.
14
+ *
15
+ * Licensed under the Apache License, Version 2.0 (the "License");
16
+ * you may not use this file except in compliance with the License.
17
+ * You may obtain a copy of the License at
18
+ *
19
+ * http://www.apache.org/licenses/LICENSE-2.0
20
+ *
21
+ * Unless required by applicable law or agreed to in writing, software
22
+ * distributed under the License is distributed on an "AS IS" BASIS,
23
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
24
+ * See the License for the specific language governing permissions and
25
+ * limitations under the License.
26
+ */
27
+
28
+ function assert(value, message) {
29
+ if (!value) throw new Error(message || 'Assertion error');
30
+ }
31
+ function debugAssert(value, message) {
32
+ if (isUnderTest() && !value) throw new Error(message);
33
+ }
34
+ const debugEnv = (0, _env.getFromENV)('PWDEBUG') || '';
35
+ function debugMode() {
36
+ if (debugEnv === 'console') return 'console';
37
+ if (debugEnv === '0' || debugEnv === 'false') return '';
38
+ return debugEnv ? 'inspector' : '';
39
+ }
40
+ let _isUnderTest = !!process.env.PWTEST_UNDER_TEST;
41
+ function setUnderTest() {
42
+ _isUnderTest = true;
43
+ }
44
+ function isUnderTest() {
45
+ return _isUnderTest;
46
+ }
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.debugLogger = exports.RecentLogsCollector = void 0;
7
+ var _utilsBundle = require("../utilsBundle");
8
+ var _fs = _interopRequireDefault(require("fs"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /**
11
+ * Copyright (c) Microsoft Corporation.
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+
26
+ const debugLoggerColorMap = {
27
+ 'api': 45,
28
+ // cyan
29
+ 'protocol': 34,
30
+ // green
31
+ 'install': 34,
32
+ // green
33
+ 'download': 34,
34
+ // green
35
+ 'browser': 0,
36
+ // reset
37
+ 'socks': 92,
38
+ // purple
39
+ 'client-certificates': 92,
40
+ // purple
41
+ 'error': 160,
42
+ // red,
43
+ 'channel': 33,
44
+ // blue
45
+ 'server': 45,
46
+ // cyan
47
+ 'server:channel': 34,
48
+ // green
49
+ 'server:metadata': 33 // blue
50
+ };
51
+ class DebugLogger {
52
+ constructor() {
53
+ this._debuggers = new Map();
54
+ if (process.env.DEBUG_FILE) {
55
+ const ansiRegex = new RegExp(['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|'), 'g');
56
+ const stream = _fs.default.createWriteStream(process.env.DEBUG_FILE);
57
+ _utilsBundle.debug.log = data => {
58
+ stream.write(data.replace(ansiRegex, ''));
59
+ stream.write('\n');
60
+ };
61
+ }
62
+ }
63
+ log(name, message) {
64
+ let cachedDebugger = this._debuggers.get(name);
65
+ if (!cachedDebugger) {
66
+ cachedDebugger = (0, _utilsBundle.debug)(`pw:${name}`);
67
+ this._debuggers.set(name, cachedDebugger);
68
+ cachedDebugger.color = debugLoggerColorMap[name] || 0;
69
+ }
70
+ cachedDebugger(message);
71
+ }
72
+ isEnabled(name) {
73
+ return _utilsBundle.debug.enabled(`pw:${name}`);
74
+ }
75
+ }
76
+ const debugLogger = exports.debugLogger = new DebugLogger();
77
+ const kLogCount = 150;
78
+ class RecentLogsCollector {
79
+ constructor() {
80
+ this._logs = [];
81
+ }
82
+ log(message) {
83
+ this._logs.push(message);
84
+ if (this._logs.length === kLogCount * 2) this._logs.splice(0, kLogCount);
85
+ }
86
+ recentLogs() {
87
+ if (this._logs.length > kLogCount) return this._logs.slice(-kLogCount);
88
+ return this._logs;
89
+ }
90
+ }
91
+ exports.RecentLogsCollector = RecentLogsCollector;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getAsBooleanFromENV = getAsBooleanFromENV;
7
+ exports.getFromENV = getFromENV;
8
+ exports.getPackageManager = getPackageManager;
9
+ exports.getPackageManagerExecCommand = getPackageManagerExecCommand;
10
+ /**
11
+ * Copyright (c) Microsoft Corporation.
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+
26
+ function getFromENV(name) {
27
+ let value = process.env[name];
28
+ value = value === undefined ? process.env[`npm_config_${name.toLowerCase()}`] : value;
29
+ value = value === undefined ? process.env[`npm_package_config_${name.toLowerCase()}`] : value;
30
+ return value;
31
+ }
32
+ function getAsBooleanFromENV(name, defaultValue) {
33
+ const value = getFromENV(name);
34
+ if (value === 'false' || value === '0') return false;
35
+ if (value) return true;
36
+ return !!defaultValue;
37
+ }
38
+ function getPackageManager() {
39
+ const env = process.env.npm_config_user_agent || '';
40
+ if (env.includes('yarn')) return 'yarn';
41
+ if (env.includes('pnpm')) return 'pnpm';
42
+ return 'npm';
43
+ }
44
+ function getPackageManagerExecCommand() {
45
+ const packageManager = getPackageManager();
46
+ if (packageManager === 'yarn') return 'yarn';
47
+ if (packageManager === 'pnpm') return 'pnpm exec';
48
+ return 'npx';
49
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.eventsHelper = void 0;
7
+ /**
8
+ * Copyright 2017 Google Inc. All rights reserved.
9
+ * Modifications 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 EventsHelper {
25
+ static addEventListener(emitter, eventName, handler) {
26
+ emitter.on(eventName, handler);
27
+ return {
28
+ emitter,
29
+ eventName,
30
+ handler
31
+ };
32
+ }
33
+ static removeEventListeners(listeners) {
34
+ for (const listener of listeners) listener.emitter.removeListener(listener.eventName, listener.handler);
35
+ listeners.splice(0, listeners.length);
36
+ }
37
+ }
38
+ const eventsHelper = exports.eventsHelper = EventsHelper;