@checkly/playwright-core 1.48.23 → 1.48.24-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 (71) hide show
  1. package/lib/generated/clockSource.js +1 -2
  2. package/lib/generated/consoleApiSource.js +1 -2
  3. package/lib/generated/injectedScriptSource.js +1 -2
  4. package/lib/generated/pollingRecorderSource.js +1 -2
  5. package/lib/generated/utilityScriptSource.js +1 -2
  6. package/lib/generated/webSocketMockSource.js +1 -2
  7. package/lib/vite/traceViewer/assets/codeMirrorModule-lDjkI8Ax.js +24 -0
  8. package/lib/vite/traceViewer/assets/inspectorTab-BPzhNk9r.js +64 -0
  9. package/lib/vite/traceViewer/assets/workbench-DLv_q9ji.js +9 -0
  10. package/lib/vite/traceViewer/embedded.BIubxTi3.js +2 -0
  11. package/lib/vite/traceViewer/embedded.html +3 -3
  12. package/lib/vite/traceViewer/index.DPD22sZn.js +2 -0
  13. package/lib/vite/traceViewer/index.html +3 -3
  14. package/lib/vite/traceViewer/recorder.BaRuS6Pc.js +2 -0
  15. package/lib/vite/traceViewer/recorder.html +2 -2
  16. package/lib/vite/traceViewer/uiMode.B11wexdJ.js +5 -0
  17. package/lib/vite/traceViewer/uiMode.html +3 -3
  18. package/package.json +1 -1
  19. package/lib/client/clientStackTrace.js +0 -65
  20. package/lib/client/fileUtils.js +0 -31
  21. package/lib/client/platform.js +0 -71
  22. package/lib/client/timeoutSettings.js +0 -65
  23. package/lib/client/webSocket.js +0 -106
  24. package/lib/server/callLog.js +0 -79
  25. package/lib/server/harBackend.js +0 -157
  26. package/lib/server/localUtils.js +0 -203
  27. package/lib/server/recorder/chat.js +0 -177
  28. package/lib/server/storageScript.js +0 -160
  29. package/lib/server/timeoutSettings.js +0 -74
  30. package/lib/server/utils/ascii.js +0 -31
  31. package/lib/server/utils/comparators.js +0 -159
  32. package/lib/server/utils/crypto.js +0 -171
  33. package/lib/server/utils/debug.js +0 -38
  34. package/lib/server/utils/debugLogger.js +0 -93
  35. package/lib/server/utils/env.js +0 -53
  36. package/lib/server/utils/eventsHelper.js +0 -38
  37. package/lib/server/utils/expectUtils.js +0 -33
  38. package/lib/server/utils/fileUtils.js +0 -204
  39. package/lib/server/utils/happyEyeballs.js +0 -209
  40. package/lib/server/utils/hostPlatform.js +0 -145
  41. package/lib/server/utils/httpServer.js +0 -233
  42. package/lib/server/utils/image_tools/colorUtils.js +0 -98
  43. package/lib/server/utils/image_tools/compare.js +0 -108
  44. package/lib/server/utils/image_tools/imageChannel.js +0 -70
  45. package/lib/server/utils/image_tools/stats.js +0 -102
  46. package/lib/server/utils/linuxUtils.js +0 -58
  47. package/lib/server/utils/network.js +0 -160
  48. package/lib/server/utils/nodePlatform.js +0 -140
  49. package/lib/server/utils/pipeTransport.js +0 -82
  50. package/lib/server/utils/processLauncher.js +0 -248
  51. package/lib/server/utils/profiler.js +0 -52
  52. package/lib/server/utils/socksProxy.js +0 -570
  53. package/lib/server/utils/spawnAsync.js +0 -45
  54. package/lib/server/utils/task.js +0 -58
  55. package/lib/server/utils/userAgent.js +0 -91
  56. package/lib/server/utils/wsServer.js +0 -128
  57. package/lib/server/utils/zipFile.js +0 -75
  58. package/lib/server/utils/zones.js +0 -54
  59. package/lib/utils/isomorphic/ariaSnapshot.js +0 -392
  60. package/lib/utils/isomorphic/assert.js +0 -25
  61. package/lib/utils/isomorphic/colors.js +0 -65
  62. package/lib/utils/isomorphic/headers.js +0 -52
  63. package/lib/utils/isomorphic/manualPromise.js +0 -107
  64. package/lib/utils/isomorphic/multimap.js +0 -73
  65. package/lib/utils/isomorphic/rtti.js +0 -41
  66. package/lib/utils/isomorphic/semaphore.js +0 -51
  67. package/lib/utils/isomorphic/stackTrace.js +0 -169
  68. package/lib/utils/isomorphic/time.js +0 -25
  69. package/lib/utils/isomorphic/timeoutRunner.js +0 -66
  70. package/lib/utils/isomorphic/types.js +0 -5
  71. package/lib/utils.js +0 -447
@@ -1,209 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createConnectionAsync = createConnectionAsync;
7
- exports.createSocket = createSocket;
8
- exports.createTLSSocket = createTLSSocket;
9
- exports.httpsHappyEyeballsAgent = exports.httpHappyEyeballsTimings = exports.httpHappyEyeballsAgent = void 0;
10
- exports.timingForSocket = timingForSocket;
11
- var _dns = _interopRequireDefault(require("dns"));
12
- var _http = _interopRequireDefault(require("http"));
13
- var _https = _interopRequireDefault(require("https"));
14
- var _net = _interopRequireDefault(require("net"));
15
- var _tls = _interopRequireDefault(require("tls"));
16
- var _assert = require("../../utils/isomorphic/assert");
17
- var _manualPromise = require("../../utils/isomorphic/manualPromise");
18
- var _time = require("../../utils/isomorphic/time");
19
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
20
- /**
21
- * Copyright (c) Microsoft Corporation.
22
- *
23
- * Licensed under the Apache License, Version 2.0 (the "License");
24
- * you may not use this file except in compliance with the License.
25
- * You may obtain a copy of the License at
26
- *
27
- * http://www.apache.org/licenses/LICENSE-2.0
28
- *
29
- * Unless required by applicable law or agreed to in writing, software
30
- * distributed under the License is distributed on an "AS IS" BASIS,
31
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32
- * See the License for the specific language governing permissions and
33
- * limitations under the License.
34
- */
35
-
36
- // Implementation(partial) of Happy Eyeballs 2 algorithm described in
37
- // https://www.rfc-editor.org/rfc/rfc8305
38
-
39
- // Same as in Chromium (https://source.chromium.org/chromium/chromium/src/+/5666ff4f5077a7e2f72902f3a95f5d553ea0d88d:net/socket/transport_connect_job.cc;l=102)
40
- const connectionAttemptDelayMs = 300;
41
- const checklyTimings = {
42
- values: {
43
- startTimeNow: 0,
44
- socket: 0,
45
- connect: 0,
46
- lookup: 0
47
- },
48
- agent: false
49
- };
50
- const kDNSLookupAt = Symbol('kDNSLookupAt');
51
- const kTCPConnectionAt = Symbol('kTCPConnectionAt');
52
- class HttpHappyEyeballsAgent extends _http.default.Agent {
53
- createConnection(options, oncreate) {
54
- // There is no ambiguity in case of IP address.
55
- if (_net.default.isIP(clientRequestArgsToHostName(options))) return _net.default.createConnection(options);
56
- createConnectionAsync(options, oncreate, /* useTLS */false).catch(err => oncreate === null || oncreate === void 0 ? void 0 : oncreate(err));
57
- }
58
- }
59
- class HttpsHappyEyeballsAgent extends _https.default.Agent {
60
- createConnection(options, oncreate) {
61
- checklyTimings.values.startTimeNow = performance.now();
62
- checklyTimings.agent = true;
63
- // There is no ambiguity in case of IP address.
64
- if (_net.default.isIP(clientRequestArgsToHostName(options))) return _tls.default.connect(options);
65
- createConnectionAsync(options, oncreate, /* useTLS */true).catch(err => oncreate === null || oncreate === void 0 ? void 0 : oncreate(err));
66
- }
67
- }
68
-
69
- // These options are aligned with the default Node.js globalAgent options.
70
- const httpsHappyEyeballsAgent = exports.httpsHappyEyeballsAgent = new HttpsHappyEyeballsAgent({
71
- keepAlive: true
72
- });
73
- const httpHappyEyeballsAgent = exports.httpHappyEyeballsAgent = new HttpHappyEyeballsAgent({
74
- keepAlive: true
75
- });
76
- const httpHappyEyeballsTimings = exports.httpHappyEyeballsTimings = checklyTimings;
77
- async function createSocket(host, port) {
78
- return new Promise((resolve, reject) => {
79
- if (_net.default.isIP(host)) {
80
- const socket = _net.default.createConnection({
81
- host,
82
- port
83
- });
84
- socket.on('connect', () => resolve(socket));
85
- socket.on('error', error => reject(error));
86
- } else {
87
- createConnectionAsync({
88
- host,
89
- port
90
- }, (err, socket) => {
91
- if (err) reject(err);
92
- if (socket) resolve(socket);
93
- }, /* useTLS */false).catch(err => reject(err));
94
- }
95
- });
96
- }
97
- async function createTLSSocket(options) {
98
- return new Promise((resolve, reject) => {
99
- (0, _assert.assert)(options.host, 'host is required');
100
- if (_net.default.isIP(options.host)) {
101
- const socket = _tls.default.connect(options);
102
- socket.on('secureConnect', () => resolve(socket));
103
- socket.on('error', error => reject(error));
104
- } else {
105
- createConnectionAsync(options, (err, socket) => {
106
- if (err) reject(err);
107
- if (socket) {
108
- socket.on('secureConnect', () => resolve(socket));
109
- socket.on('error', error => reject(error));
110
- }
111
- }, true).catch(err => reject(err));
112
- }
113
- });
114
- }
115
- async function createConnectionAsync(options, oncreate, useTLS) {
116
- const lookup = options.__testHookLookup || lookupAddresses;
117
- const hostname = clientRequestArgsToHostName(options);
118
- const addresses = await lookup(hostname);
119
- const dnsLookupAt = (0, _time.monotonicTime)();
120
- const sockets = new Set();
121
- let firstError;
122
- let errorCount = 0;
123
- const handleError = (socket, err) => {
124
- if (!sockets.delete(socket)) return;
125
- ++errorCount;
126
- firstError !== null && firstError !== void 0 ? firstError : firstError = err;
127
- if (errorCount === addresses.length) oncreate === null || oncreate === void 0 || oncreate(firstError);
128
- };
129
- const connected = new _manualPromise.ManualPromise();
130
- for (const {
131
- address
132
- } of addresses) {
133
- const socket = useTLS ? _tls.default.connect({
134
- ...options,
135
- port: options.port,
136
- host: address,
137
- servername: hostname
138
- }) : _net.default.createConnection({
139
- ...options,
140
- port: options.port,
141
- host: address
142
- });
143
-
144
- // Socket created
145
- checklyTimings.values.socket = performance.now() - checklyTimings.values.startTimeNow;
146
- socket[kDNSLookupAt] = dnsLookupAt;
147
-
148
- // Each socket may fire only one of 'connect', 'timeout' or 'error' events.
149
- // None of these events are fired after socket.destroy() is called.
150
- socket.on('connect', () => {
151
- socket[kTCPConnectionAt] = (0, _time.monotonicTime)();
152
- checklyTimings.values.connect = performance.now() - checklyTimings.values.startTimeNow;
153
- connected.resolve();
154
- oncreate === null || oncreate === void 0 || oncreate(null, socket);
155
- // TODO: Cache the result?
156
- // Close other outstanding sockets.
157
- sockets.delete(socket);
158
- for (const s of sockets) s.destroy();
159
- sockets.clear();
160
- });
161
- socket.on('timeout', () => {
162
- // Timeout is not an error, so we have to manually close the socket.
163
- socket.destroy();
164
- handleError(socket, new Error('Connection timeout'));
165
- });
166
- socket.on('error', e => handleError(socket, e));
167
- sockets.add(socket);
168
- await Promise.race([connected, new Promise(f => setTimeout(f, connectionAttemptDelayMs))]);
169
- if (connected.isDone()) break;
170
- }
171
- }
172
- async function lookupAddresses(hostname) {
173
- const addresses = await _dns.default.promises.lookup(hostname, {
174
- all: true,
175
- family: 0,
176
- verbatim: true
177
- });
178
- checklyTimings.values.lookup = performance.now() - checklyTimings.values.startTimeNow;
179
- let firstFamily = addresses.filter(({
180
- family
181
- }) => family === 6);
182
- let secondFamily = addresses.filter(({
183
- family
184
- }) => family === 4);
185
- // Make sure first address in the list is the same as in the original order.
186
- if (firstFamily.length && firstFamily[0] !== addresses[0]) {
187
- const tmp = firstFamily;
188
- firstFamily = secondFamily;
189
- secondFamily = tmp;
190
- }
191
- const result = [];
192
- // Alternate ipv6 and ipv4 addresses.
193
- for (let i = 0; i < Math.max(firstFamily.length, secondFamily.length); i++) {
194
- if (firstFamily[i]) result.push(firstFamily[i]);
195
- if (secondFamily[i]) result.push(secondFamily[i]);
196
- }
197
- return result;
198
- }
199
- function clientRequestArgsToHostName(options) {
200
- if (options.hostname) return options.hostname;
201
- if (options.host) return options.host;
202
- throw new Error('Either options.hostname or options.host must be provided');
203
- }
204
- function timingForSocket(socket) {
205
- return {
206
- dnsLookupAt: socket[kDNSLookupAt],
207
- tcpConnectionAt: socket[kTCPConnectionAt]
208
- };
209
- }
@@ -1,145 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isOfficiallySupportedPlatform = exports.hostPlatform = void 0;
7
- var _os = _interopRequireDefault(require("os"));
8
- var _linuxUtils = require("./linuxUtils");
9
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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 calculatePlatform() {
27
- if (process.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE) {
28
- return {
29
- hostPlatform: process.env.PLAYWRIGHT_HOST_PLATFORM_OVERRIDE,
30
- isOfficiallySupportedPlatform: false
31
- };
32
- }
33
- const platform = _os.default.platform();
34
- if (platform === 'darwin') {
35
- const ver = _os.default.release().split('.').map(a => parseInt(a, 10));
36
- let macVersion = '';
37
- if (ver[0] < 18) {
38
- // Everything before 10.14 is considered 10.13.
39
- macVersion = 'mac10.13';
40
- } else if (ver[0] === 18) {
41
- macVersion = 'mac10.14';
42
- } else if (ver[0] === 19) {
43
- macVersion = 'mac10.15';
44
- } else {
45
- // ver[0] >= 20
46
- const LAST_STABLE_MACOS_MAJOR_VERSION = 15;
47
- // Best-effort support for MacOS beta versions.
48
- macVersion = 'mac' + Math.min(ver[0] - 9, LAST_STABLE_MACOS_MAJOR_VERSION);
49
- // BigSur is the first version that might run on Apple Silicon.
50
- if (_os.default.cpus().some(cpu => cpu.model.includes('Apple'))) macVersion += '-arm64';
51
- }
52
- return {
53
- hostPlatform: macVersion,
54
- isOfficiallySupportedPlatform: true
55
- };
56
- }
57
- if (platform === 'linux') {
58
- if (!['x64', 'arm64'].includes(_os.default.arch())) return {
59
- hostPlatform: '<unknown>',
60
- isOfficiallySupportedPlatform: false
61
- };
62
- const archSuffix = '-' + _os.default.arch();
63
- const distroInfo = (0, _linuxUtils.getLinuxDistributionInfoSync)();
64
-
65
- // Pop!_OS is ubuntu-based and has the same versions.
66
- // KDE Neon is ubuntu-based and has the same versions.
67
- // TUXEDO OS is ubuntu-based and has the same versions.
68
- if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'ubuntu' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'pop' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'neon' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'tuxedo') {
69
- const isUbuntu = (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'ubuntu';
70
- const version = distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.version;
71
- const major = parseInt(distroInfo.version, 10);
72
- if (major < 20) return {
73
- hostPlatform: 'ubuntu18.04' + archSuffix,
74
- isOfficiallySupportedPlatform: false
75
- };
76
- if (major < 22) return {
77
- hostPlatform: 'ubuntu20.04' + archSuffix,
78
- isOfficiallySupportedPlatform: isUbuntu && version === '20.04'
79
- };
80
- if (major < 24) return {
81
- hostPlatform: 'ubuntu22.04' + archSuffix,
82
- isOfficiallySupportedPlatform: isUbuntu && version === '22.04'
83
- };
84
- if (major < 26) return {
85
- hostPlatform: 'ubuntu24.04' + archSuffix,
86
- isOfficiallySupportedPlatform: isUbuntu && version === '24.04'
87
- };
88
- return {
89
- hostPlatform: 'ubuntu' + distroInfo.version + archSuffix,
90
- isOfficiallySupportedPlatform: false
91
- };
92
- }
93
- // Linux Mint is ubuntu-based but does not have the same versions
94
- if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'linuxmint') {
95
- const mintMajor = parseInt(distroInfo.version, 10);
96
- if (mintMajor <= 20) return {
97
- hostPlatform: 'ubuntu20.04' + archSuffix,
98
- isOfficiallySupportedPlatform: false
99
- };
100
- if (mintMajor === 21) return {
101
- hostPlatform: 'ubuntu22.04' + archSuffix,
102
- isOfficiallySupportedPlatform: false
103
- };
104
- return {
105
- hostPlatform: 'ubuntu24.04' + archSuffix,
106
- isOfficiallySupportedPlatform: false
107
- };
108
- }
109
- if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'debian' || (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'raspbian') {
110
- const isOfficiallySupportedPlatform = (distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.id) === 'debian';
111
- if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.version) === '11') return {
112
- hostPlatform: 'debian11' + archSuffix,
113
- isOfficiallySupportedPlatform
114
- };
115
- if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.version) === '12') return {
116
- hostPlatform: 'debian12' + archSuffix,
117
- isOfficiallySupportedPlatform
118
- };
119
- // use most recent supported release for 'debian testing' and 'unstable'.
120
- // they never include a numeric version entry in /etc/os-release.
121
- if ((distroInfo === null || distroInfo === void 0 ? void 0 : distroInfo.version) === '') return {
122
- hostPlatform: 'debian12' + archSuffix,
123
- isOfficiallySupportedPlatform
124
- };
125
- }
126
- return {
127
- hostPlatform: 'ubuntu20.04' + archSuffix,
128
- isOfficiallySupportedPlatform: false
129
- };
130
- }
131
- if (platform === 'win32') return {
132
- hostPlatform: 'win64',
133
- isOfficiallySupportedPlatform: true
134
- };
135
- return {
136
- hostPlatform: '<unknown>',
137
- isOfficiallySupportedPlatform: false
138
- };
139
- }
140
- const {
141
- hostPlatform,
142
- isOfficiallySupportedPlatform
143
- } = calculatePlatform();
144
- exports.isOfficiallySupportedPlatform = isOfficiallySupportedPlatform;
145
- exports.hostPlatform = hostPlatform;
@@ -1,233 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.HttpServer = void 0;
7
- var _fs = _interopRequireDefault(require("fs"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _utilsBundle = require("../../utilsBundle");
10
- var _crypto = require("./crypto");
11
- var _assert = require("../../utils/isomorphic/assert");
12
- var _manualPromise = require("../../utils/isomorphic/manualPromise");
13
- var _network = require("./network");
14
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
- /**
16
- * Copyright (c) Microsoft Corporation.
17
- *
18
- * Licensed under the Apache License, Version 2.0 (the "License");
19
- * you may not use this file except in compliance with the License.
20
- * You may obtain a copy of the License at
21
- *
22
- * http://www.apache.org/licenses/LICENSE-2.0
23
- *
24
- * Unless required by applicable law or agreed to in writing, software
25
- * distributed under the License is distributed on an "AS IS" BASIS,
26
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
- * See the License for the specific language governing permissions and
28
- * limitations under the License.
29
- */
30
-
31
- class HttpServer {
32
- constructor() {
33
- this._server = void 0;
34
- this._urlPrefixPrecise = '';
35
- this._urlPrefixHumanReadable = '';
36
- this._port = 0;
37
- this._started = false;
38
- this._routes = [];
39
- this._wsGuid = void 0;
40
- this._server = (0, _network.createHttpServer)(this._onRequest.bind(this));
41
- }
42
- server() {
43
- return this._server;
44
- }
45
- routePrefix(prefix, handler) {
46
- this._routes.push({
47
- prefix,
48
- handler
49
- });
50
- }
51
- routePath(path, handler) {
52
- this._routes.push({
53
- exact: path,
54
- handler
55
- });
56
- }
57
- port() {
58
- return this._port;
59
- }
60
- async _tryStart(port, host) {
61
- const errorPromise = new _manualPromise.ManualPromise();
62
- const errorListener = error => errorPromise.reject(error);
63
- this._server.on('error', errorListener);
64
- try {
65
- this._server.listen(port, host);
66
- await Promise.race([new Promise(cb => this._server.once('listening', cb)), errorPromise]);
67
- } finally {
68
- this._server.removeListener('error', errorListener);
69
- }
70
- }
71
- createWebSocket(transport, guid) {
72
- (0, _assert.assert)(!this._wsGuid, 'can only create one main websocket transport per server');
73
- this._wsGuid = guid || (0, _crypto.createGuid)();
74
- const wss = new _utilsBundle.wsServer({
75
- server: this._server,
76
- path: '/' + this._wsGuid
77
- });
78
- wss.on('connection', ws => {
79
- transport.onconnect();
80
- transport.sendEvent = (method, params) => ws.send(JSON.stringify({
81
- method,
82
- params
83
- }));
84
- transport.close = () => ws.close();
85
- ws.on('message', async message => {
86
- const {
87
- id,
88
- method,
89
- params
90
- } = JSON.parse(String(message));
91
- try {
92
- const result = await transport.dispatch(method, params);
93
- ws.send(JSON.stringify({
94
- id,
95
- result
96
- }));
97
- } catch (e) {
98
- ws.send(JSON.stringify({
99
- id,
100
- error: String(e)
101
- }));
102
- }
103
- });
104
- ws.on('close', () => transport.onclose());
105
- ws.on('error', () => transport.onclose());
106
- });
107
- }
108
- wsGuid() {
109
- return this._wsGuid;
110
- }
111
- async start(options = {}) {
112
- (0, _assert.assert)(!this._started, 'server already started');
113
- this._started = true;
114
- const host = options.host || 'localhost';
115
- if (options.preferredPort) {
116
- try {
117
- await this._tryStart(options.preferredPort, host);
118
- } catch (e) {
119
- if (!e || !e.message || !e.message.includes('EADDRINUSE')) throw e;
120
- await this._tryStart(undefined, host);
121
- }
122
- } else {
123
- await this._tryStart(options.port, host);
124
- }
125
- const address = this._server.address();
126
- (0, _assert.assert)(address, 'Could not bind server socket');
127
- if (typeof address === 'string') {
128
- this._urlPrefixPrecise = address;
129
- this._urlPrefixHumanReadable = address;
130
- } else {
131
- this._port = address.port;
132
- const resolvedHost = address.family === 'IPv4' ? address.address : `[${address.address}]`;
133
- this._urlPrefixPrecise = `http://${resolvedHost}:${address.port}`;
134
- this._urlPrefixHumanReadable = `http://${host}:${address.port}`;
135
- }
136
- }
137
- async stop() {
138
- await new Promise(cb => this._server.close(cb));
139
- }
140
- urlPrefix(purpose) {
141
- return purpose === 'human-readable' ? this._urlPrefixHumanReadable : this._urlPrefixPrecise;
142
- }
143
- serveFile(request, response, absoluteFilePath, headers) {
144
- try {
145
- for (const [name, value] of Object.entries(headers || {})) response.setHeader(name, value);
146
- if (request.headers.range) this._serveRangeFile(request, response, absoluteFilePath);else this._serveFile(response, absoluteFilePath);
147
- return true;
148
- } catch (e) {
149
- return false;
150
- }
151
- }
152
- _serveFile(response, absoluteFilePath) {
153
- const content = _fs.default.readFileSync(absoluteFilePath);
154
- response.statusCode = 200;
155
- const contentType = _utilsBundle.mime.getType(_path.default.extname(absoluteFilePath)) || 'application/octet-stream';
156
- response.setHeader('Content-Type', contentType);
157
- response.setHeader('Content-Length', content.byteLength);
158
- response.end(content);
159
- }
160
- _serveRangeFile(request, response, absoluteFilePath) {
161
- const range = request.headers.range;
162
- if (!range || !range.startsWith('bytes=') || range.includes(', ') || [...range].filter(char => char === '-').length !== 1) {
163
- response.statusCode = 400;
164
- return response.end('Bad request');
165
- }
166
-
167
- // Parse the range header: https://datatracker.ietf.org/doc/html/rfc7233#section-2.1
168
- const [startStr, endStr] = range.replace(/bytes=/, '').split('-');
169
-
170
- // Both start and end (when passing to fs.createReadStream) and the range header are inclusive and start counting at 0.
171
- let start;
172
- let end;
173
- const size = _fs.default.statSync(absoluteFilePath).size;
174
- if (startStr !== '' && endStr === '') {
175
- // No end specified: use the whole file
176
- start = +startStr;
177
- end = size - 1;
178
- } else if (startStr === '' && endStr !== '') {
179
- // No start specified: calculate start manually
180
- start = size - +endStr;
181
- end = size - 1;
182
- } else {
183
- start = +startStr;
184
- end = +endStr;
185
- }
186
-
187
- // Handle unavailable range request
188
- if (Number.isNaN(start) || Number.isNaN(end) || start >= size || end >= size || start > end) {
189
- // Return the 416 Range Not Satisfiable: https://datatracker.ietf.org/doc/html/rfc7233#section-4.4
190
- response.writeHead(416, {
191
- 'Content-Range': `bytes */${size}`
192
- });
193
- return response.end();
194
- }
195
-
196
- // Sending Partial Content: https://datatracker.ietf.org/doc/html/rfc7233#section-4.1
197
- response.writeHead(206, {
198
- 'Content-Range': `bytes ${start}-${end}/${size}`,
199
- 'Accept-Ranges': 'bytes',
200
- 'Content-Length': end - start + 1,
201
- 'Content-Type': _utilsBundle.mime.getType(_path.default.extname(absoluteFilePath))
202
- });
203
- const readable = _fs.default.createReadStream(absoluteFilePath, {
204
- start,
205
- end
206
- });
207
- readable.pipe(response);
208
- }
209
- _onRequest(request, response) {
210
- if (request.method === 'OPTIONS') {
211
- response.writeHead(200);
212
- response.end();
213
- return;
214
- }
215
- request.on('error', () => response.end());
216
- try {
217
- if (!request.url) {
218
- response.end();
219
- return;
220
- }
221
- const url = new URL('http://localhost' + request.url);
222
- for (const route of this._routes) {
223
- if (route.exact && url.pathname === route.exact && route.handler(request, response)) return;
224
- if (route.prefix && url.pathname.startsWith(route.prefix) && route.handler(request, response)) return;
225
- }
226
- response.statusCode = 404;
227
- response.end();
228
- } catch (e) {
229
- response.end();
230
- }
231
- }
232
- }
233
- exports.HttpServer = HttpServer;
@@ -1,98 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.blendWithWhite = blendWithWhite;
7
- exports.colorDeltaE94 = colorDeltaE94;
8
- exports.rgb2gray = rgb2gray;
9
- exports.srgb2xyz = srgb2xyz;
10
- exports.xyz2lab = xyz2lab;
11
- /**
12
- * Copyright (c) Microsoft Corporation.
13
- *
14
- * Licensed under the Apache License, Version 2.0 (the 'License");
15
- * you may not use this file except in compliance with the License.
16
- * You may obtain a copy of the License at
17
- *
18
- * http://www.apache.org/licenses/LICENSE-2.0
19
- *
20
- * Unless required by applicable law or agreed to in writing, software
21
- * distributed under the License is distributed on an "AS IS" BASIS,
22
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
- * See the License for the specific language governing permissions and
24
- * limitations under the License.
25
- */
26
-
27
- function blendWithWhite(c, a) {
28
- return 255 + (c - 255) * a;
29
- }
30
- function rgb2gray(r, g, b) {
31
- // NOTE: this is the exact integer formula from SSIM.js.
32
- // See https://github.com/obartra/ssim/blob/ca8e3c6a6ff5f4f2e232239e0c3d91806f3c97d5/src/matlab/rgb2gray.ts#L56
33
- return 77 * r + 150 * g + 29 * b + 128 >> 8;
34
- }
35
-
36
- // Perceived color difference defined by CIE94.
37
- // See https://en.wikipedia.org/wiki/Color_difference#CIE94
38
- //
39
- // The result of 1.0 is a "just-noticeable difference".
40
- //
41
- // Other results interpretation (taken from http://zschuessler.github.io/DeltaE/learn/):
42
- // < 1.0 Not perceptible by human eyes.
43
- // 1-2 Perceptible through close observation.
44
- // 2-10 Perceptible at a glance.
45
- // 11-49 Colors are more similar than opposite
46
- // 100 Colors are exact opposite
47
- function colorDeltaE94(rgb1, rgb2) {
48
- const [l1, a1, b1] = xyz2lab(srgb2xyz(rgb1));
49
- const [l2, a2, b2] = xyz2lab(srgb2xyz(rgb2));
50
- const deltaL = l1 - l2;
51
- const deltaA = a1 - a2;
52
- const deltaB = b1 - b2;
53
- const c1 = Math.sqrt(a1 ** 2 + b1 ** 2);
54
- const c2 = Math.sqrt(a2 ** 2 + b2 ** 2);
55
- const deltaC = c1 - c2;
56
- let deltaH = deltaA ** 2 + deltaB ** 2 - deltaC ** 2;
57
- deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
58
- // The k1, k2, kL, kC, kH values for "graphic arts" applications.
59
- // See https://en.wikipedia.org/wiki/Color_difference#CIE94
60
- const k1 = 0.045;
61
- const k2 = 0.015;
62
- const kL = 1;
63
- const kC = 1;
64
- const kH = 1;
65
- const sC = 1.0 + k1 * c1;
66
- const sH = 1.0 + k2 * c1;
67
- const sL = 1;
68
- return Math.sqrt((deltaL / sL / kL) ** 2 + (deltaC / sC / kC) ** 2 + (deltaH / sH / kH) ** 2);
69
- }
70
-
71
- // sRGB -> 1-normalized XYZ (i.e. Y ∈ [0, 1]) with D65 illuminant
72
- // See https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ
73
- function srgb2xyz(rgb) {
74
- let r = rgb[0] / 255;
75
- let g = rgb[1] / 255;
76
- let b = rgb[2] / 255;
77
- r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
78
- g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
79
- b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
80
- return [r * 0.4124 + g * 0.3576 + b * 0.1805, r * 0.2126 + g * 0.7152 + b * 0.0722, r * 0.0193 + g * 0.1192 + b * 0.9505];
81
- }
82
- const sigma_pow2 = 6 * 6 / 29 / 29;
83
- const sigma_pow3 = 6 * 6 * 6 / 29 / 29 / 29;
84
-
85
- // 1-normalized CIE XYZ with D65 to L*a*b*
86
- // See https://en.wikipedia.org/wiki/CIELAB_color_space#From_CIEXYZ_to_CIELAB
87
- function xyz2lab(xyz) {
88
- const x = xyz[0] / 0.950489;
89
- const y = xyz[1];
90
- const z = xyz[2] / 1.088840;
91
- const fx = x > sigma_pow3 ? x ** (1 / 3) : x / 3 / sigma_pow2 + 4 / 29;
92
- const fy = y > sigma_pow3 ? y ** (1 / 3) : y / 3 / sigma_pow2 + 4 / 29;
93
- const fz = z > sigma_pow3 ? z ** (1 / 3) : z / 3 / sigma_pow2 + 4 / 29;
94
- const l = 116 * fy - 16;
95
- const a = 500 * (fx - fy);
96
- const b = 200 * (fy - fz);
97
- return [l, a, b];
98
- }