@skrillex1224/playwright-toolkit 3.0.10 → 3.0.11

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.
@@ -32,25 +32,6 @@ const state = {
32
32
  : null,
33
33
  };
34
34
 
35
- const formatFatalError = (error) => {
36
- if (error instanceof Error) {
37
- return error.stack || error.message || String(error);
38
- }
39
- try {
40
- return JSON.stringify(error);
41
- } catch {
42
- return String(error);
43
- }
44
- };
45
-
46
- const exitAfterFatal = (kind, error) => {
47
- try {
48
- console.error(`[proxy-meter] fatal ${kind}: ${formatFatalError(error)}`);
49
- } catch {}
50
- flushSnapshot();
51
- process.exit(1);
52
- };
53
-
54
35
  const getHostBucket = (host) => {
55
36
  if (!host) return null;
56
37
  if (!state.hosts[host]) {
@@ -79,21 +60,6 @@ const safeError = (error) => {
79
60
  return message.length > 240 ? message.slice(0, 240) : message;
80
61
  };
81
62
 
82
- const sendBadGateway = (res, error = null) => {
83
- if (!res || res.destroyed || res.writableEnded) return;
84
-
85
- try {
86
- if (!res.headersSent) {
87
- res.writeHead(502);
88
- res.end('Bad Gateway');
89
- return;
90
- }
91
-
92
- // Headers are already committed; the only truthful error signal left is closing the stream.
93
- res.destroy(error instanceof Error ? error : undefined);
94
- } catch {}
95
- };
96
-
97
63
  const statusLabel = (statusCode, error) => {
98
64
  const code = Number(statusCode) || 0;
99
65
  if (error || code <= 0) return 'ERR';
@@ -383,7 +349,8 @@ const forwardHttp = (req, res) => {
383
349
 
384
350
  if (!target) {
385
351
  tracker.close({ statusCode: 0, error: 'invalid_target_url' });
386
- sendBadGateway(res);
352
+ res.writeHead(502);
353
+ res.end('Bad Gateway');
387
354
  return;
388
355
  }
389
356
 
@@ -414,19 +381,7 @@ const forwardHttp = (req, res) => {
414
381
  let responseStatus = 0;
415
382
  const proxyReq = http.request(requestOptions, (proxyRes) => {
416
383
  responseStatus = Number(proxyRes.statusCode) || 0;
417
- if (res.destroyed || res.writableEnded) {
418
- tracker.close({ statusCode: responseStatus || 499, error: 'client_response_closed' });
419
- proxyRes.resume();
420
- return;
421
- }
422
- try {
423
- res.writeHead(responseStatus || 502, proxyRes.headers);
424
- } catch (error) {
425
- tracker.close({ statusCode: responseStatus, error: safeError(error) });
426
- proxyRes.resume();
427
- sendBadGateway(res, error);
428
- return;
429
- }
384
+ res.writeHead(responseStatus || 502, proxyRes.headers);
430
385
  proxyRes.on('data', (chunk) => {
431
386
  const size = chunk?.length || 0;
432
387
  addTraffic(hostname, 'in', size);
@@ -457,7 +412,8 @@ const forwardHttp = (req, res) => {
457
412
 
458
413
  proxyReq.on('error', (error) => {
459
414
  tracker.close({ statusCode: responseStatus, error: safeError(error) });
460
- sendBadGateway(res, error);
415
+ res.writeHead(502);
416
+ res.end('Bad Gateway');
461
417
  });
462
418
  };
463
419
 
@@ -589,7 +545,5 @@ const shutdown = () => {
589
545
  process.exit(0);
590
546
  };
591
547
 
592
- process.on('uncaughtException', (error) => exitAfterFatal('uncaughtException', error));
593
- process.on('unhandledRejection', (error) => exitAfterFatal('unhandledRejection', error));
594
548
  process.on('SIGINT', shutdown);
595
549
  process.on('SIGTERM', shutdown);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@skrillex1224/playwright-toolkit",
3
- "version": "3.0.10",
3
+ "version": "3.0.11",
4
4
  "description": "一个在 Apify/Crawlee Actor 中启用实时截图视图的实用工具库。",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",