@bigbinary/neeto-playwright-commons 1.8.16 → 1.8.18
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.
- package/index.cjs.js +2857 -41
- package/index.cjs.js.map +1 -1
- package/index.d.ts +6 -3
- package/index.js +2851 -37
- package/index.js.map +1 -1
- package/package.json +4 -1
package/index.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import test, { expect, test as test$1, defineConfig, devices } from '@playwright/test';
|
|
2
|
-
import * as require$$0 from 'fs';
|
|
2
|
+
import * as require$$0$1 from 'fs';
|
|
3
3
|
import require$$0__default from 'fs';
|
|
4
4
|
import { isEmpty as isEmpty$1, isNil, isNotNil, mergeDeepLeft, mergeAll } from 'ramda';
|
|
5
5
|
import { faker } from '@faker-js/faker';
|
|
6
6
|
import MailosaurClient from 'mailosaur';
|
|
7
7
|
import dayjs from 'dayjs';
|
|
8
|
-
import require$$
|
|
9
|
-
import require$$0$
|
|
10
|
-
import require$$0$2 from '
|
|
11
|
-
import require$$0$
|
|
12
|
-
import require$$0$
|
|
8
|
+
import require$$1 from 'tty';
|
|
9
|
+
import require$$0$3 from 'util';
|
|
10
|
+
import require$$0$2 from 'os';
|
|
11
|
+
import require$$0$4 from 'path';
|
|
12
|
+
import require$$0$5 from 'stream';
|
|
13
|
+
import require$$0$6 from 'events';
|
|
13
14
|
import { getI18nInstance, initI18n } from 'playwright-i18next-fixture';
|
|
14
15
|
import { humanize, isNotEmpty } from '@bigbinary/neeto-cist';
|
|
15
16
|
import require$$3 from 'crypto';
|
|
@@ -40,7 +41,7 @@ const joinString = (string1, string2, string3 = "", separator = " ") => {
|
|
|
40
41
|
};
|
|
41
42
|
const readFileSyncIfExists = (path = STORAGE_STATE) => {
|
|
42
43
|
try {
|
|
43
|
-
return JSON.parse(require$$0.readFileSync(path, "utf8"));
|
|
44
|
+
return JSON.parse(require$$0$1.readFileSync(path, "utf8"));
|
|
44
45
|
}
|
|
45
46
|
catch (error) {
|
|
46
47
|
return {};
|
|
@@ -49,7 +50,7 @@ const readFileSyncIfExists = (path = STORAGE_STATE) => {
|
|
|
49
50
|
const getGlobalUserState = () => { var _a; return (_a = readFileSyncIfExists()) === null || _a === void 0 ? void 0 : _a.user; };
|
|
50
51
|
const writeDataToFile = data => {
|
|
51
52
|
try {
|
|
52
|
-
require$$0.writeFileSync(STORAGE_STATE, data, "utf8");
|
|
53
|
+
require$$0$1.writeFileSync(STORAGE_STATE, data, "utf8");
|
|
53
54
|
}
|
|
54
55
|
catch (error) {
|
|
55
56
|
console.log(error); // eslint-disable-line
|
|
@@ -62,7 +63,7 @@ const updateCredentials = ({ key, value }) => {
|
|
|
62
63
|
return writeDataToFile(JSON.stringify(data));
|
|
63
64
|
};
|
|
64
65
|
const removeCredentialFile = () => {
|
|
65
|
-
require$$0.unlink(STORAGE_STATE, error => {
|
|
66
|
+
require$$0$1.unlink(STORAGE_STATE, error => {
|
|
66
67
|
if (!error)
|
|
67
68
|
return;
|
|
68
69
|
console.log(error); // eslint-disable-line
|
|
@@ -158,12 +159,12 @@ const COMMON_SELECTORS = {
|
|
|
158
159
|
|
|
159
160
|
class CustomCommands {
|
|
160
161
|
constructor(page, request, baseURL = process.env.BASE_URL) {
|
|
161
|
-
this.interceptMultipleResponses = ({ responseUrl = "", times = 1, baseUrl, customPageContext, timeout = 35000, } = {}) => {
|
|
162
|
+
this.interceptMultipleResponses = ({ responseUrl = "", responseStatus = 200, times = 1, baseUrl, customPageContext, timeout = 35000, } = {}) => {
|
|
162
163
|
const pageContext = customPageContext !== null && customPageContext !== void 0 ? customPageContext : this.page;
|
|
163
164
|
return Promise.all([...new Array(times)].map(() => pageContext.waitForResponse((response) => {
|
|
164
165
|
var _a, _b, _c;
|
|
165
166
|
if (response.request().resourceType() === "xhr" &&
|
|
166
|
-
response.status() ===
|
|
167
|
+
response.status() === responseStatus &&
|
|
167
168
|
response.url().includes(responseUrl) &&
|
|
168
169
|
response.url().startsWith((_a = baseUrl !== null && baseUrl !== void 0 ? baseUrl : this.baseURL) !== null && _a !== void 0 ? _a : "") &&
|
|
169
170
|
!this.responses.includes((_b = response.headers()) === null || _b === void 0 ? void 0 : _b["x-request-id"])) {
|
|
@@ -315,6 +316,2821 @@ const generateStagingData = (product = "invoice") => {
|
|
|
315
316
|
};
|
|
316
317
|
};
|
|
317
318
|
|
|
319
|
+
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
320
|
+
|
|
321
|
+
function getDefaultExportFromCjs (x) {
|
|
322
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function getAugmentedNamespace(n) {
|
|
326
|
+
var f = n.default;
|
|
327
|
+
if (typeof f == "function") {
|
|
328
|
+
var a = function () {
|
|
329
|
+
return f.apply(this, arguments);
|
|
330
|
+
};
|
|
331
|
+
a.prototype = f.prototype;
|
|
332
|
+
} else a = {};
|
|
333
|
+
Object.defineProperty(a, '__esModule', {value: true});
|
|
334
|
+
Object.keys(n).forEach(function (k) {
|
|
335
|
+
var d = Object.getOwnPropertyDescriptor(n, k);
|
|
336
|
+
Object.defineProperty(a, k, d.get ? d : {
|
|
337
|
+
enumerable: true,
|
|
338
|
+
get: function () {
|
|
339
|
+
return n[k];
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
return a;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
var src = {exports: {}};
|
|
347
|
+
|
|
348
|
+
var browser$1 = {exports: {}};
|
|
349
|
+
|
|
350
|
+
/**
|
|
351
|
+
* Helpers.
|
|
352
|
+
*/
|
|
353
|
+
|
|
354
|
+
var ms;
|
|
355
|
+
var hasRequiredMs;
|
|
356
|
+
|
|
357
|
+
function requireMs () {
|
|
358
|
+
if (hasRequiredMs) return ms;
|
|
359
|
+
hasRequiredMs = 1;
|
|
360
|
+
var s = 1000;
|
|
361
|
+
var m = s * 60;
|
|
362
|
+
var h = m * 60;
|
|
363
|
+
var d = h * 24;
|
|
364
|
+
var w = d * 7;
|
|
365
|
+
var y = d * 365.25;
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* Parse or format the given `val`.
|
|
369
|
+
*
|
|
370
|
+
* Options:
|
|
371
|
+
*
|
|
372
|
+
* - `long` verbose formatting [false]
|
|
373
|
+
*
|
|
374
|
+
* @param {String|Number} val
|
|
375
|
+
* @param {Object} [options]
|
|
376
|
+
* @throws {Error} throw an error if val is not a non-empty string or a number
|
|
377
|
+
* @return {String|Number}
|
|
378
|
+
* @api public
|
|
379
|
+
*/
|
|
380
|
+
|
|
381
|
+
ms = function(val, options) {
|
|
382
|
+
options = options || {};
|
|
383
|
+
var type = typeof val;
|
|
384
|
+
if (type === 'string' && val.length > 0) {
|
|
385
|
+
return parse(val);
|
|
386
|
+
} else if (type === 'number' && isFinite(val)) {
|
|
387
|
+
return options.long ? fmtLong(val) : fmtShort(val);
|
|
388
|
+
}
|
|
389
|
+
throw new Error(
|
|
390
|
+
'val is not a non-empty string or a valid number. val=' +
|
|
391
|
+
JSON.stringify(val)
|
|
392
|
+
);
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Parse the given `str` and return milliseconds.
|
|
397
|
+
*
|
|
398
|
+
* @param {String} str
|
|
399
|
+
* @return {Number}
|
|
400
|
+
* @api private
|
|
401
|
+
*/
|
|
402
|
+
|
|
403
|
+
function parse(str) {
|
|
404
|
+
str = String(str);
|
|
405
|
+
if (str.length > 100) {
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
|
409
|
+
str
|
|
410
|
+
);
|
|
411
|
+
if (!match) {
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
var n = parseFloat(match[1]);
|
|
415
|
+
var type = (match[2] || 'ms').toLowerCase();
|
|
416
|
+
switch (type) {
|
|
417
|
+
case 'years':
|
|
418
|
+
case 'year':
|
|
419
|
+
case 'yrs':
|
|
420
|
+
case 'yr':
|
|
421
|
+
case 'y':
|
|
422
|
+
return n * y;
|
|
423
|
+
case 'weeks':
|
|
424
|
+
case 'week':
|
|
425
|
+
case 'w':
|
|
426
|
+
return n * w;
|
|
427
|
+
case 'days':
|
|
428
|
+
case 'day':
|
|
429
|
+
case 'd':
|
|
430
|
+
return n * d;
|
|
431
|
+
case 'hours':
|
|
432
|
+
case 'hour':
|
|
433
|
+
case 'hrs':
|
|
434
|
+
case 'hr':
|
|
435
|
+
case 'h':
|
|
436
|
+
return n * h;
|
|
437
|
+
case 'minutes':
|
|
438
|
+
case 'minute':
|
|
439
|
+
case 'mins':
|
|
440
|
+
case 'min':
|
|
441
|
+
case 'm':
|
|
442
|
+
return n * m;
|
|
443
|
+
case 'seconds':
|
|
444
|
+
case 'second':
|
|
445
|
+
case 'secs':
|
|
446
|
+
case 'sec':
|
|
447
|
+
case 's':
|
|
448
|
+
return n * s;
|
|
449
|
+
case 'milliseconds':
|
|
450
|
+
case 'millisecond':
|
|
451
|
+
case 'msecs':
|
|
452
|
+
case 'msec':
|
|
453
|
+
case 'ms':
|
|
454
|
+
return n;
|
|
455
|
+
default:
|
|
456
|
+
return undefined;
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Short format for `ms`.
|
|
462
|
+
*
|
|
463
|
+
* @param {Number} ms
|
|
464
|
+
* @return {String}
|
|
465
|
+
* @api private
|
|
466
|
+
*/
|
|
467
|
+
|
|
468
|
+
function fmtShort(ms) {
|
|
469
|
+
var msAbs = Math.abs(ms);
|
|
470
|
+
if (msAbs >= d) {
|
|
471
|
+
return Math.round(ms / d) + 'd';
|
|
472
|
+
}
|
|
473
|
+
if (msAbs >= h) {
|
|
474
|
+
return Math.round(ms / h) + 'h';
|
|
475
|
+
}
|
|
476
|
+
if (msAbs >= m) {
|
|
477
|
+
return Math.round(ms / m) + 'm';
|
|
478
|
+
}
|
|
479
|
+
if (msAbs >= s) {
|
|
480
|
+
return Math.round(ms / s) + 's';
|
|
481
|
+
}
|
|
482
|
+
return ms + 'ms';
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
/**
|
|
486
|
+
* Long format for `ms`.
|
|
487
|
+
*
|
|
488
|
+
* @param {Number} ms
|
|
489
|
+
* @return {String}
|
|
490
|
+
* @api private
|
|
491
|
+
*/
|
|
492
|
+
|
|
493
|
+
function fmtLong(ms) {
|
|
494
|
+
var msAbs = Math.abs(ms);
|
|
495
|
+
if (msAbs >= d) {
|
|
496
|
+
return plural(ms, msAbs, d, 'day');
|
|
497
|
+
}
|
|
498
|
+
if (msAbs >= h) {
|
|
499
|
+
return plural(ms, msAbs, h, 'hour');
|
|
500
|
+
}
|
|
501
|
+
if (msAbs >= m) {
|
|
502
|
+
return plural(ms, msAbs, m, 'minute');
|
|
503
|
+
}
|
|
504
|
+
if (msAbs >= s) {
|
|
505
|
+
return plural(ms, msAbs, s, 'second');
|
|
506
|
+
}
|
|
507
|
+
return ms + ' ms';
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* Pluralization helper.
|
|
512
|
+
*/
|
|
513
|
+
|
|
514
|
+
function plural(ms, msAbs, n, name) {
|
|
515
|
+
var isPlural = msAbs >= n * 1.5;
|
|
516
|
+
return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
|
517
|
+
}
|
|
518
|
+
return ms;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
var common$7;
|
|
522
|
+
var hasRequiredCommon;
|
|
523
|
+
|
|
524
|
+
function requireCommon () {
|
|
525
|
+
if (hasRequiredCommon) return common$7;
|
|
526
|
+
hasRequiredCommon = 1;
|
|
527
|
+
/**
|
|
528
|
+
* This is the common logic for both the Node.js and web browser
|
|
529
|
+
* implementations of `debug()`.
|
|
530
|
+
*/
|
|
531
|
+
|
|
532
|
+
function setup(env) {
|
|
533
|
+
createDebug.debug = createDebug;
|
|
534
|
+
createDebug.default = createDebug;
|
|
535
|
+
createDebug.coerce = coerce;
|
|
536
|
+
createDebug.disable = disable;
|
|
537
|
+
createDebug.enable = enable;
|
|
538
|
+
createDebug.enabled = enabled;
|
|
539
|
+
createDebug.humanize = requireMs();
|
|
540
|
+
createDebug.destroy = destroy;
|
|
541
|
+
|
|
542
|
+
Object.keys(env).forEach(key => {
|
|
543
|
+
createDebug[key] = env[key];
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
/**
|
|
547
|
+
* The currently active debug mode names, and names to skip.
|
|
548
|
+
*/
|
|
549
|
+
|
|
550
|
+
createDebug.names = [];
|
|
551
|
+
createDebug.skips = [];
|
|
552
|
+
|
|
553
|
+
/**
|
|
554
|
+
* Map of special "%n" handling functions, for the debug "format" argument.
|
|
555
|
+
*
|
|
556
|
+
* Valid key names are a single, lower or upper-case letter, i.e. "n" and "N".
|
|
557
|
+
*/
|
|
558
|
+
createDebug.formatters = {};
|
|
559
|
+
|
|
560
|
+
/**
|
|
561
|
+
* Selects a color for a debug namespace
|
|
562
|
+
* @param {String} namespace The namespace string for the debug instance to be colored
|
|
563
|
+
* @return {Number|String} An ANSI color code for the given namespace
|
|
564
|
+
* @api private
|
|
565
|
+
*/
|
|
566
|
+
function selectColor(namespace) {
|
|
567
|
+
let hash = 0;
|
|
568
|
+
|
|
569
|
+
for (let i = 0; i < namespace.length; i++) {
|
|
570
|
+
hash = ((hash << 5) - hash) + namespace.charCodeAt(i);
|
|
571
|
+
hash |= 0; // Convert to 32bit integer
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
|
575
|
+
}
|
|
576
|
+
createDebug.selectColor = selectColor;
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Create a debugger with the given `namespace`.
|
|
580
|
+
*
|
|
581
|
+
* @param {String} namespace
|
|
582
|
+
* @return {Function}
|
|
583
|
+
* @api public
|
|
584
|
+
*/
|
|
585
|
+
function createDebug(namespace) {
|
|
586
|
+
let prevTime;
|
|
587
|
+
let enableOverride = null;
|
|
588
|
+
let namespacesCache;
|
|
589
|
+
let enabledCache;
|
|
590
|
+
|
|
591
|
+
function debug(...args) {
|
|
592
|
+
// Disabled?
|
|
593
|
+
if (!debug.enabled) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
const self = debug;
|
|
598
|
+
|
|
599
|
+
// Set `diff` timestamp
|
|
600
|
+
const curr = Number(new Date());
|
|
601
|
+
const ms = curr - (prevTime || curr);
|
|
602
|
+
self.diff = ms;
|
|
603
|
+
self.prev = prevTime;
|
|
604
|
+
self.curr = curr;
|
|
605
|
+
prevTime = curr;
|
|
606
|
+
|
|
607
|
+
args[0] = createDebug.coerce(args[0]);
|
|
608
|
+
|
|
609
|
+
if (typeof args[0] !== 'string') {
|
|
610
|
+
// Anything else let's inspect with %O
|
|
611
|
+
args.unshift('%O');
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
// Apply any `formatters` transformations
|
|
615
|
+
let index = 0;
|
|
616
|
+
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => {
|
|
617
|
+
// If we encounter an escaped % then don't increase the array index
|
|
618
|
+
if (match === '%%') {
|
|
619
|
+
return '%';
|
|
620
|
+
}
|
|
621
|
+
index++;
|
|
622
|
+
const formatter = createDebug.formatters[format];
|
|
623
|
+
if (typeof formatter === 'function') {
|
|
624
|
+
const val = args[index];
|
|
625
|
+
match = formatter.call(self, val);
|
|
626
|
+
|
|
627
|
+
// Now we need to remove `args[index]` since it's inlined in the `format`
|
|
628
|
+
args.splice(index, 1);
|
|
629
|
+
index--;
|
|
630
|
+
}
|
|
631
|
+
return match;
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
// Apply env-specific formatting (colors, etc.)
|
|
635
|
+
createDebug.formatArgs.call(self, args);
|
|
636
|
+
|
|
637
|
+
const logFn = self.log || createDebug.log;
|
|
638
|
+
logFn.apply(self, args);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
debug.namespace = namespace;
|
|
642
|
+
debug.useColors = createDebug.useColors();
|
|
643
|
+
debug.color = createDebug.selectColor(namespace);
|
|
644
|
+
debug.extend = extend;
|
|
645
|
+
debug.destroy = createDebug.destroy; // XXX Temporary. Will be removed in the next major release.
|
|
646
|
+
|
|
647
|
+
Object.defineProperty(debug, 'enabled', {
|
|
648
|
+
enumerable: true,
|
|
649
|
+
configurable: false,
|
|
650
|
+
get: () => {
|
|
651
|
+
if (enableOverride !== null) {
|
|
652
|
+
return enableOverride;
|
|
653
|
+
}
|
|
654
|
+
if (namespacesCache !== createDebug.namespaces) {
|
|
655
|
+
namespacesCache = createDebug.namespaces;
|
|
656
|
+
enabledCache = createDebug.enabled(namespace);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
return enabledCache;
|
|
660
|
+
},
|
|
661
|
+
set: v => {
|
|
662
|
+
enableOverride = v;
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
// Env-specific initialization logic for debug instances
|
|
667
|
+
if (typeof createDebug.init === 'function') {
|
|
668
|
+
createDebug.init(debug);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
return debug;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
function extend(namespace, delimiter) {
|
|
675
|
+
const newDebug = createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
|
676
|
+
newDebug.log = this.log;
|
|
677
|
+
return newDebug;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
/**
|
|
681
|
+
* Enables a debug mode by namespaces. This can include modes
|
|
682
|
+
* separated by a colon and wildcards.
|
|
683
|
+
*
|
|
684
|
+
* @param {String} namespaces
|
|
685
|
+
* @api public
|
|
686
|
+
*/
|
|
687
|
+
function enable(namespaces) {
|
|
688
|
+
createDebug.save(namespaces);
|
|
689
|
+
createDebug.namespaces = namespaces;
|
|
690
|
+
|
|
691
|
+
createDebug.names = [];
|
|
692
|
+
createDebug.skips = [];
|
|
693
|
+
|
|
694
|
+
let i;
|
|
695
|
+
const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
|
696
|
+
const len = split.length;
|
|
697
|
+
|
|
698
|
+
for (i = 0; i < len; i++) {
|
|
699
|
+
if (!split[i]) {
|
|
700
|
+
// ignore empty strings
|
|
701
|
+
continue;
|
|
702
|
+
}
|
|
703
|
+
|
|
704
|
+
namespaces = split[i].replace(/\*/g, '.*?');
|
|
705
|
+
|
|
706
|
+
if (namespaces[0] === '-') {
|
|
707
|
+
createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
|
|
708
|
+
} else {
|
|
709
|
+
createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
|
710
|
+
}
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
/**
|
|
715
|
+
* Disable debug output.
|
|
716
|
+
*
|
|
717
|
+
* @return {String} namespaces
|
|
718
|
+
* @api public
|
|
719
|
+
*/
|
|
720
|
+
function disable() {
|
|
721
|
+
const namespaces = [
|
|
722
|
+
...createDebug.names.map(toNamespace),
|
|
723
|
+
...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
|
|
724
|
+
].join(',');
|
|
725
|
+
createDebug.enable('');
|
|
726
|
+
return namespaces;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
/**
|
|
730
|
+
* Returns true if the given mode name is enabled, false otherwise.
|
|
731
|
+
*
|
|
732
|
+
* @param {String} name
|
|
733
|
+
* @return {Boolean}
|
|
734
|
+
* @api public
|
|
735
|
+
*/
|
|
736
|
+
function enabled(name) {
|
|
737
|
+
if (name[name.length - 1] === '*') {
|
|
738
|
+
return true;
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
let i;
|
|
742
|
+
let len;
|
|
743
|
+
|
|
744
|
+
for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
|
745
|
+
if (createDebug.skips[i].test(name)) {
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
}
|
|
749
|
+
|
|
750
|
+
for (i = 0, len = createDebug.names.length; i < len; i++) {
|
|
751
|
+
if (createDebug.names[i].test(name)) {
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
return false;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
/**
|
|
760
|
+
* Convert regexp to namespace
|
|
761
|
+
*
|
|
762
|
+
* @param {RegExp} regxep
|
|
763
|
+
* @return {String} namespace
|
|
764
|
+
* @api private
|
|
765
|
+
*/
|
|
766
|
+
function toNamespace(regexp) {
|
|
767
|
+
return regexp.toString()
|
|
768
|
+
.substring(2, regexp.toString().length - 2)
|
|
769
|
+
.replace(/\.\*\?$/, '*');
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
/**
|
|
773
|
+
* Coerce `val`.
|
|
774
|
+
*
|
|
775
|
+
* @param {Mixed} val
|
|
776
|
+
* @return {Mixed}
|
|
777
|
+
* @api private
|
|
778
|
+
*/
|
|
779
|
+
function coerce(val) {
|
|
780
|
+
if (val instanceof Error) {
|
|
781
|
+
return val.stack || val.message;
|
|
782
|
+
}
|
|
783
|
+
return val;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* XXX DO NOT USE. This is a temporary stub function.
|
|
788
|
+
* XXX It WILL be removed in the next major release.
|
|
789
|
+
*/
|
|
790
|
+
function destroy() {
|
|
791
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
createDebug.enable(createDebug.load());
|
|
795
|
+
|
|
796
|
+
return createDebug;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
common$7 = setup;
|
|
800
|
+
return common$7;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/* eslint-env browser */
|
|
804
|
+
|
|
805
|
+
var hasRequiredBrowser;
|
|
806
|
+
|
|
807
|
+
function requireBrowser () {
|
|
808
|
+
if (hasRequiredBrowser) return browser$1.exports;
|
|
809
|
+
hasRequiredBrowser = 1;
|
|
810
|
+
(function (module, exports) {
|
|
811
|
+
/**
|
|
812
|
+
* This is the web browser implementation of `debug()`.
|
|
813
|
+
*/
|
|
814
|
+
|
|
815
|
+
exports.formatArgs = formatArgs;
|
|
816
|
+
exports.save = save;
|
|
817
|
+
exports.load = load;
|
|
818
|
+
exports.useColors = useColors;
|
|
819
|
+
exports.storage = localstorage();
|
|
820
|
+
exports.destroy = (() => {
|
|
821
|
+
let warned = false;
|
|
822
|
+
|
|
823
|
+
return () => {
|
|
824
|
+
if (!warned) {
|
|
825
|
+
warned = true;
|
|
826
|
+
console.warn('Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.');
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
})();
|
|
830
|
+
|
|
831
|
+
/**
|
|
832
|
+
* Colors.
|
|
833
|
+
*/
|
|
834
|
+
|
|
835
|
+
exports.colors = [
|
|
836
|
+
'#0000CC',
|
|
837
|
+
'#0000FF',
|
|
838
|
+
'#0033CC',
|
|
839
|
+
'#0033FF',
|
|
840
|
+
'#0066CC',
|
|
841
|
+
'#0066FF',
|
|
842
|
+
'#0099CC',
|
|
843
|
+
'#0099FF',
|
|
844
|
+
'#00CC00',
|
|
845
|
+
'#00CC33',
|
|
846
|
+
'#00CC66',
|
|
847
|
+
'#00CC99',
|
|
848
|
+
'#00CCCC',
|
|
849
|
+
'#00CCFF',
|
|
850
|
+
'#3300CC',
|
|
851
|
+
'#3300FF',
|
|
852
|
+
'#3333CC',
|
|
853
|
+
'#3333FF',
|
|
854
|
+
'#3366CC',
|
|
855
|
+
'#3366FF',
|
|
856
|
+
'#3399CC',
|
|
857
|
+
'#3399FF',
|
|
858
|
+
'#33CC00',
|
|
859
|
+
'#33CC33',
|
|
860
|
+
'#33CC66',
|
|
861
|
+
'#33CC99',
|
|
862
|
+
'#33CCCC',
|
|
863
|
+
'#33CCFF',
|
|
864
|
+
'#6600CC',
|
|
865
|
+
'#6600FF',
|
|
866
|
+
'#6633CC',
|
|
867
|
+
'#6633FF',
|
|
868
|
+
'#66CC00',
|
|
869
|
+
'#66CC33',
|
|
870
|
+
'#9900CC',
|
|
871
|
+
'#9900FF',
|
|
872
|
+
'#9933CC',
|
|
873
|
+
'#9933FF',
|
|
874
|
+
'#99CC00',
|
|
875
|
+
'#99CC33',
|
|
876
|
+
'#CC0000',
|
|
877
|
+
'#CC0033',
|
|
878
|
+
'#CC0066',
|
|
879
|
+
'#CC0099',
|
|
880
|
+
'#CC00CC',
|
|
881
|
+
'#CC00FF',
|
|
882
|
+
'#CC3300',
|
|
883
|
+
'#CC3333',
|
|
884
|
+
'#CC3366',
|
|
885
|
+
'#CC3399',
|
|
886
|
+
'#CC33CC',
|
|
887
|
+
'#CC33FF',
|
|
888
|
+
'#CC6600',
|
|
889
|
+
'#CC6633',
|
|
890
|
+
'#CC9900',
|
|
891
|
+
'#CC9933',
|
|
892
|
+
'#CCCC00',
|
|
893
|
+
'#CCCC33',
|
|
894
|
+
'#FF0000',
|
|
895
|
+
'#FF0033',
|
|
896
|
+
'#FF0066',
|
|
897
|
+
'#FF0099',
|
|
898
|
+
'#FF00CC',
|
|
899
|
+
'#FF00FF',
|
|
900
|
+
'#FF3300',
|
|
901
|
+
'#FF3333',
|
|
902
|
+
'#FF3366',
|
|
903
|
+
'#FF3399',
|
|
904
|
+
'#FF33CC',
|
|
905
|
+
'#FF33FF',
|
|
906
|
+
'#FF6600',
|
|
907
|
+
'#FF6633',
|
|
908
|
+
'#FF9900',
|
|
909
|
+
'#FF9933',
|
|
910
|
+
'#FFCC00',
|
|
911
|
+
'#FFCC33'
|
|
912
|
+
];
|
|
913
|
+
|
|
914
|
+
/**
|
|
915
|
+
* Currently only WebKit-based Web Inspectors, Firefox >= v31,
|
|
916
|
+
* and the Firebug extension (any Firefox version) are known
|
|
917
|
+
* to support "%c" CSS customizations.
|
|
918
|
+
*
|
|
919
|
+
* TODO: add a `localStorage` variable to explicitly enable/disable colors
|
|
920
|
+
*/
|
|
921
|
+
|
|
922
|
+
// eslint-disable-next-line complexity
|
|
923
|
+
function useColors() {
|
|
924
|
+
// NB: In an Electron preload script, document will be defined but not fully
|
|
925
|
+
// initialized. Since we know we're in Chrome, we'll just detect this case
|
|
926
|
+
// explicitly
|
|
927
|
+
if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
|
928
|
+
return true;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// Internet Explorer and Edge do not support colors.
|
|
932
|
+
if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
|
933
|
+
return false;
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// Is webkit? http://stackoverflow.com/a/16459606/376773
|
|
937
|
+
// document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
|
|
938
|
+
return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
|
|
939
|
+
// Is firebug? http://stackoverflow.com/a/398120/376773
|
|
940
|
+
(typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
|
|
941
|
+
// Is firefox >= v31?
|
|
942
|
+
// https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
|
|
943
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
|
|
944
|
+
// Double check webkit in userAgent just in case we are in a worker
|
|
945
|
+
(typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/**
|
|
949
|
+
* Colorize log arguments if enabled.
|
|
950
|
+
*
|
|
951
|
+
* @api public
|
|
952
|
+
*/
|
|
953
|
+
|
|
954
|
+
function formatArgs(args) {
|
|
955
|
+
args[0] = (this.useColors ? '%c' : '') +
|
|
956
|
+
this.namespace +
|
|
957
|
+
(this.useColors ? ' %c' : ' ') +
|
|
958
|
+
args[0] +
|
|
959
|
+
(this.useColors ? '%c ' : ' ') +
|
|
960
|
+
'+' + module.exports.humanize(this.diff);
|
|
961
|
+
|
|
962
|
+
if (!this.useColors) {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
|
|
966
|
+
const c = 'color: ' + this.color;
|
|
967
|
+
args.splice(1, 0, c, 'color: inherit');
|
|
968
|
+
|
|
969
|
+
// The final "%c" is somewhat tricky, because there could be other
|
|
970
|
+
// arguments passed either before or after the %c, so we need to
|
|
971
|
+
// figure out the correct index to insert the CSS into
|
|
972
|
+
let index = 0;
|
|
973
|
+
let lastC = 0;
|
|
974
|
+
args[0].replace(/%[a-zA-Z%]/g, match => {
|
|
975
|
+
if (match === '%%') {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
index++;
|
|
979
|
+
if (match === '%c') {
|
|
980
|
+
// We only are interested in the *last* %c
|
|
981
|
+
// (the user may have provided their own)
|
|
982
|
+
lastC = index;
|
|
983
|
+
}
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
args.splice(lastC, 0, c);
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
/**
|
|
990
|
+
* Invokes `console.debug()` when available.
|
|
991
|
+
* No-op when `console.debug` is not a "function".
|
|
992
|
+
* If `console.debug` is not available, falls back
|
|
993
|
+
* to `console.log`.
|
|
994
|
+
*
|
|
995
|
+
* @api public
|
|
996
|
+
*/
|
|
997
|
+
exports.log = console.debug || console.log || (() => {});
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Save `namespaces`.
|
|
1001
|
+
*
|
|
1002
|
+
* @param {String} namespaces
|
|
1003
|
+
* @api private
|
|
1004
|
+
*/
|
|
1005
|
+
function save(namespaces) {
|
|
1006
|
+
try {
|
|
1007
|
+
if (namespaces) {
|
|
1008
|
+
exports.storage.setItem('debug', namespaces);
|
|
1009
|
+
} else {
|
|
1010
|
+
exports.storage.removeItem('debug');
|
|
1011
|
+
}
|
|
1012
|
+
} catch (error) {
|
|
1013
|
+
// Swallow
|
|
1014
|
+
// XXX (@Qix-) should we be logging these?
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/**
|
|
1019
|
+
* Load `namespaces`.
|
|
1020
|
+
*
|
|
1021
|
+
* @return {String} returns the previously persisted debug modes
|
|
1022
|
+
* @api private
|
|
1023
|
+
*/
|
|
1024
|
+
function load() {
|
|
1025
|
+
let r;
|
|
1026
|
+
try {
|
|
1027
|
+
r = exports.storage.getItem('debug');
|
|
1028
|
+
} catch (error) {
|
|
1029
|
+
// Swallow
|
|
1030
|
+
// XXX (@Qix-) should we be logging these?
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
// If debug isn't set in LS, and we're in Electron, try to load $DEBUG
|
|
1034
|
+
if (!r && typeof process !== 'undefined' && 'env' in process) {
|
|
1035
|
+
r = process.env.DEBUG;
|
|
1036
|
+
}
|
|
1037
|
+
|
|
1038
|
+
return r;
|
|
1039
|
+
}
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* Localstorage attempts to return the localstorage.
|
|
1043
|
+
*
|
|
1044
|
+
* This is necessary because safari throws
|
|
1045
|
+
* when a user disables cookies/localstorage
|
|
1046
|
+
* and you attempt to access it.
|
|
1047
|
+
*
|
|
1048
|
+
* @return {LocalStorage}
|
|
1049
|
+
* @api private
|
|
1050
|
+
*/
|
|
1051
|
+
|
|
1052
|
+
function localstorage() {
|
|
1053
|
+
try {
|
|
1054
|
+
// TVMLKit (Apple TV JS Runtime) does not have a window object, just localStorage in the global context
|
|
1055
|
+
// The Browser also has localStorage in the global context.
|
|
1056
|
+
return localStorage;
|
|
1057
|
+
} catch (error) {
|
|
1058
|
+
// Swallow
|
|
1059
|
+
// XXX (@Qix-) should we be logging these?
|
|
1060
|
+
}
|
|
1061
|
+
}
|
|
1062
|
+
|
|
1063
|
+
module.exports = requireCommon()(exports);
|
|
1064
|
+
|
|
1065
|
+
const {formatters} = module.exports;
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
* Map %j to `JSON.stringify()`, since no Web Inspectors do that by default.
|
|
1069
|
+
*/
|
|
1070
|
+
|
|
1071
|
+
formatters.j = function (v) {
|
|
1072
|
+
try {
|
|
1073
|
+
return JSON.stringify(v);
|
|
1074
|
+
} catch (error) {
|
|
1075
|
+
return '[UnexpectedJSONParseError]: ' + error.message;
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
} (browser$1, browser$1.exports));
|
|
1079
|
+
return browser$1.exports;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
var node = {exports: {}};
|
|
1083
|
+
|
|
1084
|
+
var hasFlag;
|
|
1085
|
+
var hasRequiredHasFlag;
|
|
1086
|
+
|
|
1087
|
+
function requireHasFlag () {
|
|
1088
|
+
if (hasRequiredHasFlag) return hasFlag;
|
|
1089
|
+
hasRequiredHasFlag = 1;
|
|
1090
|
+
|
|
1091
|
+
hasFlag = (flag, argv = process.argv) => {
|
|
1092
|
+
const prefix = flag.startsWith('-') ? '' : (flag.length === 1 ? '-' : '--');
|
|
1093
|
+
const position = argv.indexOf(prefix + flag);
|
|
1094
|
+
const terminatorPosition = argv.indexOf('--');
|
|
1095
|
+
return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
|
|
1096
|
+
};
|
|
1097
|
+
return hasFlag;
|
|
1098
|
+
}
|
|
1099
|
+
|
|
1100
|
+
var supportsColor_1;
|
|
1101
|
+
var hasRequiredSupportsColor;
|
|
1102
|
+
|
|
1103
|
+
function requireSupportsColor () {
|
|
1104
|
+
if (hasRequiredSupportsColor) return supportsColor_1;
|
|
1105
|
+
hasRequiredSupportsColor = 1;
|
|
1106
|
+
const os = require$$0$2;
|
|
1107
|
+
const tty = require$$1;
|
|
1108
|
+
const hasFlag = requireHasFlag();
|
|
1109
|
+
|
|
1110
|
+
const {env} = process;
|
|
1111
|
+
|
|
1112
|
+
let forceColor;
|
|
1113
|
+
if (hasFlag('no-color') ||
|
|
1114
|
+
hasFlag('no-colors') ||
|
|
1115
|
+
hasFlag('color=false') ||
|
|
1116
|
+
hasFlag('color=never')) {
|
|
1117
|
+
forceColor = 0;
|
|
1118
|
+
} else if (hasFlag('color') ||
|
|
1119
|
+
hasFlag('colors') ||
|
|
1120
|
+
hasFlag('color=true') ||
|
|
1121
|
+
hasFlag('color=always')) {
|
|
1122
|
+
forceColor = 1;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
if ('FORCE_COLOR' in env) {
|
|
1126
|
+
if (env.FORCE_COLOR === 'true') {
|
|
1127
|
+
forceColor = 1;
|
|
1128
|
+
} else if (env.FORCE_COLOR === 'false') {
|
|
1129
|
+
forceColor = 0;
|
|
1130
|
+
} else {
|
|
1131
|
+
forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
function translateLevel(level) {
|
|
1136
|
+
if (level === 0) {
|
|
1137
|
+
return false;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
return {
|
|
1141
|
+
level,
|
|
1142
|
+
hasBasic: true,
|
|
1143
|
+
has256: level >= 2,
|
|
1144
|
+
has16m: level >= 3
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
function supportsColor(haveStream, streamIsTTY) {
|
|
1149
|
+
if (forceColor === 0) {
|
|
1150
|
+
return 0;
|
|
1151
|
+
}
|
|
1152
|
+
|
|
1153
|
+
if (hasFlag('color=16m') ||
|
|
1154
|
+
hasFlag('color=full') ||
|
|
1155
|
+
hasFlag('color=truecolor')) {
|
|
1156
|
+
return 3;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
if (hasFlag('color=256')) {
|
|
1160
|
+
return 2;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
if (haveStream && !streamIsTTY && forceColor === undefined) {
|
|
1164
|
+
return 0;
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
const min = forceColor || 0;
|
|
1168
|
+
|
|
1169
|
+
if (env.TERM === 'dumb') {
|
|
1170
|
+
return min;
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
if (process.platform === 'win32') {
|
|
1174
|
+
// Windows 10 build 10586 is the first Windows release that supports 256 colors.
|
|
1175
|
+
// Windows 10 build 14931 is the first release that supports 16m/TrueColor.
|
|
1176
|
+
const osRelease = os.release().split('.');
|
|
1177
|
+
if (
|
|
1178
|
+
Number(osRelease[0]) >= 10 &&
|
|
1179
|
+
Number(osRelease[2]) >= 10586
|
|
1180
|
+
) {
|
|
1181
|
+
return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1184
|
+
return 1;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
if ('CI' in env) {
|
|
1188
|
+
if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
|
|
1189
|
+
return 1;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
return min;
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
if ('TEAMCITY_VERSION' in env) {
|
|
1196
|
+
return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
if (env.COLORTERM === 'truecolor') {
|
|
1200
|
+
return 3;
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
if ('TERM_PROGRAM' in env) {
|
|
1204
|
+
const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
1205
|
+
|
|
1206
|
+
switch (env.TERM_PROGRAM) {
|
|
1207
|
+
case 'iTerm.app':
|
|
1208
|
+
return version >= 3 ? 3 : 2;
|
|
1209
|
+
case 'Apple_Terminal':
|
|
1210
|
+
return 2;
|
|
1211
|
+
// No default
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
if (/-256(color)?$/i.test(env.TERM)) {
|
|
1216
|
+
return 2;
|
|
1217
|
+
}
|
|
1218
|
+
|
|
1219
|
+
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
|
|
1220
|
+
return 1;
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
if ('COLORTERM' in env) {
|
|
1224
|
+
return 1;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
return min;
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
function getSupportLevel(stream) {
|
|
1231
|
+
const level = supportsColor(stream, stream && stream.isTTY);
|
|
1232
|
+
return translateLevel(level);
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
supportsColor_1 = {
|
|
1236
|
+
supportsColor: getSupportLevel,
|
|
1237
|
+
stdout: translateLevel(supportsColor(true, tty.isatty(1))),
|
|
1238
|
+
stderr: translateLevel(supportsColor(true, tty.isatty(2)))
|
|
1239
|
+
};
|
|
1240
|
+
return supportsColor_1;
|
|
1241
|
+
}
|
|
1242
|
+
|
|
1243
|
+
/**
|
|
1244
|
+
* Module dependencies.
|
|
1245
|
+
*/
|
|
1246
|
+
|
|
1247
|
+
var hasRequiredNode;
|
|
1248
|
+
|
|
1249
|
+
function requireNode () {
|
|
1250
|
+
if (hasRequiredNode) return node.exports;
|
|
1251
|
+
hasRequiredNode = 1;
|
|
1252
|
+
(function (module, exports) {
|
|
1253
|
+
const tty = require$$1;
|
|
1254
|
+
const util = require$$0$3;
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* This is the Node.js implementation of `debug()`.
|
|
1258
|
+
*/
|
|
1259
|
+
|
|
1260
|
+
exports.init = init;
|
|
1261
|
+
exports.log = log;
|
|
1262
|
+
exports.formatArgs = formatArgs;
|
|
1263
|
+
exports.save = save;
|
|
1264
|
+
exports.load = load;
|
|
1265
|
+
exports.useColors = useColors;
|
|
1266
|
+
exports.destroy = util.deprecate(
|
|
1267
|
+
() => {},
|
|
1268
|
+
'Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.'
|
|
1269
|
+
);
|
|
1270
|
+
|
|
1271
|
+
/**
|
|
1272
|
+
* Colors.
|
|
1273
|
+
*/
|
|
1274
|
+
|
|
1275
|
+
exports.colors = [6, 2, 3, 4, 5, 1];
|
|
1276
|
+
|
|
1277
|
+
try {
|
|
1278
|
+
// Optional dependency (as in, doesn't need to be installed, NOT like optionalDependencies in package.json)
|
|
1279
|
+
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
1280
|
+
const supportsColor = requireSupportsColor();
|
|
1281
|
+
|
|
1282
|
+
if (supportsColor && (supportsColor.stderr || supportsColor).level >= 2) {
|
|
1283
|
+
exports.colors = [
|
|
1284
|
+
20,
|
|
1285
|
+
21,
|
|
1286
|
+
26,
|
|
1287
|
+
27,
|
|
1288
|
+
32,
|
|
1289
|
+
33,
|
|
1290
|
+
38,
|
|
1291
|
+
39,
|
|
1292
|
+
40,
|
|
1293
|
+
41,
|
|
1294
|
+
42,
|
|
1295
|
+
43,
|
|
1296
|
+
44,
|
|
1297
|
+
45,
|
|
1298
|
+
56,
|
|
1299
|
+
57,
|
|
1300
|
+
62,
|
|
1301
|
+
63,
|
|
1302
|
+
68,
|
|
1303
|
+
69,
|
|
1304
|
+
74,
|
|
1305
|
+
75,
|
|
1306
|
+
76,
|
|
1307
|
+
77,
|
|
1308
|
+
78,
|
|
1309
|
+
79,
|
|
1310
|
+
80,
|
|
1311
|
+
81,
|
|
1312
|
+
92,
|
|
1313
|
+
93,
|
|
1314
|
+
98,
|
|
1315
|
+
99,
|
|
1316
|
+
112,
|
|
1317
|
+
113,
|
|
1318
|
+
128,
|
|
1319
|
+
129,
|
|
1320
|
+
134,
|
|
1321
|
+
135,
|
|
1322
|
+
148,
|
|
1323
|
+
149,
|
|
1324
|
+
160,
|
|
1325
|
+
161,
|
|
1326
|
+
162,
|
|
1327
|
+
163,
|
|
1328
|
+
164,
|
|
1329
|
+
165,
|
|
1330
|
+
166,
|
|
1331
|
+
167,
|
|
1332
|
+
168,
|
|
1333
|
+
169,
|
|
1334
|
+
170,
|
|
1335
|
+
171,
|
|
1336
|
+
172,
|
|
1337
|
+
173,
|
|
1338
|
+
178,
|
|
1339
|
+
179,
|
|
1340
|
+
184,
|
|
1341
|
+
185,
|
|
1342
|
+
196,
|
|
1343
|
+
197,
|
|
1344
|
+
198,
|
|
1345
|
+
199,
|
|
1346
|
+
200,
|
|
1347
|
+
201,
|
|
1348
|
+
202,
|
|
1349
|
+
203,
|
|
1350
|
+
204,
|
|
1351
|
+
205,
|
|
1352
|
+
206,
|
|
1353
|
+
207,
|
|
1354
|
+
208,
|
|
1355
|
+
209,
|
|
1356
|
+
214,
|
|
1357
|
+
215,
|
|
1358
|
+
220,
|
|
1359
|
+
221
|
|
1360
|
+
];
|
|
1361
|
+
}
|
|
1362
|
+
} catch (error) {
|
|
1363
|
+
// Swallow - we only care if `supports-color` is available; it doesn't have to be.
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
/**
|
|
1367
|
+
* Build up the default `inspectOpts` object from the environment variables.
|
|
1368
|
+
*
|
|
1369
|
+
* $ DEBUG_COLORS=no DEBUG_DEPTH=10 DEBUG_SHOW_HIDDEN=enabled node script.js
|
|
1370
|
+
*/
|
|
1371
|
+
|
|
1372
|
+
exports.inspectOpts = Object.keys(process.env).filter(key => {
|
|
1373
|
+
return /^debug_/i.test(key);
|
|
1374
|
+
}).reduce((obj, key) => {
|
|
1375
|
+
// Camel-case
|
|
1376
|
+
const prop = key
|
|
1377
|
+
.substring(6)
|
|
1378
|
+
.toLowerCase()
|
|
1379
|
+
.replace(/_([a-z])/g, (_, k) => {
|
|
1380
|
+
return k.toUpperCase();
|
|
1381
|
+
});
|
|
1382
|
+
|
|
1383
|
+
// Coerce string value into JS value
|
|
1384
|
+
let val = process.env[key];
|
|
1385
|
+
if (/^(yes|on|true|enabled)$/i.test(val)) {
|
|
1386
|
+
val = true;
|
|
1387
|
+
} else if (/^(no|off|false|disabled)$/i.test(val)) {
|
|
1388
|
+
val = false;
|
|
1389
|
+
} else if (val === 'null') {
|
|
1390
|
+
val = null;
|
|
1391
|
+
} else {
|
|
1392
|
+
val = Number(val);
|
|
1393
|
+
}
|
|
1394
|
+
|
|
1395
|
+
obj[prop] = val;
|
|
1396
|
+
return obj;
|
|
1397
|
+
}, {});
|
|
1398
|
+
|
|
1399
|
+
/**
|
|
1400
|
+
* Is stdout a TTY? Colored output is enabled when `true`.
|
|
1401
|
+
*/
|
|
1402
|
+
|
|
1403
|
+
function useColors() {
|
|
1404
|
+
return 'colors' in exports.inspectOpts ?
|
|
1405
|
+
Boolean(exports.inspectOpts.colors) :
|
|
1406
|
+
tty.isatty(process.stderr.fd);
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/**
|
|
1410
|
+
* Adds ANSI color escape codes if enabled.
|
|
1411
|
+
*
|
|
1412
|
+
* @api public
|
|
1413
|
+
*/
|
|
1414
|
+
|
|
1415
|
+
function formatArgs(args) {
|
|
1416
|
+
const {namespace: name, useColors} = this;
|
|
1417
|
+
|
|
1418
|
+
if (useColors) {
|
|
1419
|
+
const c = this.color;
|
|
1420
|
+
const colorCode = '\u001B[3' + (c < 8 ? c : '8;5;' + c);
|
|
1421
|
+
const prefix = ` ${colorCode};1m${name} \u001B[0m`;
|
|
1422
|
+
|
|
1423
|
+
args[0] = prefix + args[0].split('\n').join('\n' + prefix);
|
|
1424
|
+
args.push(colorCode + 'm+' + module.exports.humanize(this.diff) + '\u001B[0m');
|
|
1425
|
+
} else {
|
|
1426
|
+
args[0] = getDate() + name + ' ' + args[0];
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
|
|
1430
|
+
function getDate() {
|
|
1431
|
+
if (exports.inspectOpts.hideDate) {
|
|
1432
|
+
return '';
|
|
1433
|
+
}
|
|
1434
|
+
return new Date().toISOString() + ' ';
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
/**
|
|
1438
|
+
* Invokes `util.format()` with the specified arguments and writes to stderr.
|
|
1439
|
+
*/
|
|
1440
|
+
|
|
1441
|
+
function log(...args) {
|
|
1442
|
+
return process.stderr.write(util.format(...args) + '\n');
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
/**
|
|
1446
|
+
* Save `namespaces`.
|
|
1447
|
+
*
|
|
1448
|
+
* @param {String} namespaces
|
|
1449
|
+
* @api private
|
|
1450
|
+
*/
|
|
1451
|
+
function save(namespaces) {
|
|
1452
|
+
if (namespaces) {
|
|
1453
|
+
process.env.DEBUG = namespaces;
|
|
1454
|
+
} else {
|
|
1455
|
+
// If you set a process.env field to null or undefined, it gets cast to the
|
|
1456
|
+
// string 'null' or 'undefined'. Just delete instead.
|
|
1457
|
+
delete process.env.DEBUG;
|
|
1458
|
+
}
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1461
|
+
/**
|
|
1462
|
+
* Load `namespaces`.
|
|
1463
|
+
*
|
|
1464
|
+
* @return {String} returns the previously persisted debug modes
|
|
1465
|
+
* @api private
|
|
1466
|
+
*/
|
|
1467
|
+
|
|
1468
|
+
function load() {
|
|
1469
|
+
return process.env.DEBUG;
|
|
1470
|
+
}
|
|
1471
|
+
|
|
1472
|
+
/**
|
|
1473
|
+
* Init logic for `debug` instances.
|
|
1474
|
+
*
|
|
1475
|
+
* Create a new `inspectOpts` object in case `useColors` is set
|
|
1476
|
+
* differently for a particular `debug` instance.
|
|
1477
|
+
*/
|
|
1478
|
+
|
|
1479
|
+
function init(debug) {
|
|
1480
|
+
debug.inspectOpts = {};
|
|
1481
|
+
|
|
1482
|
+
const keys = Object.keys(exports.inspectOpts);
|
|
1483
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1484
|
+
debug.inspectOpts[keys[i]] = exports.inspectOpts[keys[i]];
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
module.exports = requireCommon()(exports);
|
|
1489
|
+
|
|
1490
|
+
const {formatters} = module.exports;
|
|
1491
|
+
|
|
1492
|
+
/**
|
|
1493
|
+
* Map %o to `util.inspect()`, all on a single line.
|
|
1494
|
+
*/
|
|
1495
|
+
|
|
1496
|
+
formatters.o = function (v) {
|
|
1497
|
+
this.inspectOpts.colors = this.useColors;
|
|
1498
|
+
return util.inspect(v, this.inspectOpts)
|
|
1499
|
+
.split('\n')
|
|
1500
|
+
.map(str => str.trim())
|
|
1501
|
+
.join(' ');
|
|
1502
|
+
};
|
|
1503
|
+
|
|
1504
|
+
/**
|
|
1505
|
+
* Map %O to `util.inspect()`, allowing multiple lines if needed.
|
|
1506
|
+
*/
|
|
1507
|
+
|
|
1508
|
+
formatters.O = function (v) {
|
|
1509
|
+
this.inspectOpts.colors = this.useColors;
|
|
1510
|
+
return util.inspect(v, this.inspectOpts);
|
|
1511
|
+
};
|
|
1512
|
+
} (node, node.exports));
|
|
1513
|
+
return node.exports;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
/**
|
|
1517
|
+
* Detect Electron renderer / nwjs process, which is node, but we should
|
|
1518
|
+
* treat as a browser.
|
|
1519
|
+
*/
|
|
1520
|
+
|
|
1521
|
+
(function (module) {
|
|
1522
|
+
if (typeof process === 'undefined' || process.type === 'renderer' || process.browser === true || process.__nwjs) {
|
|
1523
|
+
module.exports = requireBrowser();
|
|
1524
|
+
} else {
|
|
1525
|
+
module.exports = requireNode();
|
|
1526
|
+
}
|
|
1527
|
+
} (src));
|
|
1528
|
+
|
|
1529
|
+
var debug$3 = /*@__PURE__*/getDefaultExportFromCjs(src.exports);
|
|
1530
|
+
|
|
1531
|
+
/*!
|
|
1532
|
+
* playwright-extra v4.3.5 by berstend
|
|
1533
|
+
* https://github.com/berstend/puppeteer-extra/tree/master/packages/playwright-extra#readme
|
|
1534
|
+
* @license MIT
|
|
1535
|
+
*/
|
|
1536
|
+
|
|
1537
|
+
/** Node.js module loader helper */
|
|
1538
|
+
class Loader {
|
|
1539
|
+
constructor(moduleName, packageNames) {
|
|
1540
|
+
this.moduleName = moduleName;
|
|
1541
|
+
this.packageNames = packageNames;
|
|
1542
|
+
}
|
|
1543
|
+
/**
|
|
1544
|
+
* Lazy load a top level export from another module by wrapping it in a JS proxy.
|
|
1545
|
+
*
|
|
1546
|
+
* This allows us to re-export e.g. `devices` from `playwright` while redirecting direct calls
|
|
1547
|
+
* to it to the module version the user has installed, rather than shipping with a hardcoded version.
|
|
1548
|
+
*
|
|
1549
|
+
* If we don't do this and the user doesn't have the target module installed we'd throw immediately when our code is imported.
|
|
1550
|
+
*
|
|
1551
|
+
* We use a "super" Proxy defining all traps, so calls like `Object.keys(playwright.devices).length` will return the correct value.
|
|
1552
|
+
*/
|
|
1553
|
+
lazyloadExportOrDie(exportName) {
|
|
1554
|
+
const that = this;
|
|
1555
|
+
const trapHandler = Object.fromEntries(Object.getOwnPropertyNames(Reflect).map((name) => [
|
|
1556
|
+
name,
|
|
1557
|
+
function (target, ...args) {
|
|
1558
|
+
const moduleExport = that.loadModuleOrDie()[exportName];
|
|
1559
|
+
const customTarget = moduleExport;
|
|
1560
|
+
const result = Reflect[name](customTarget || target, ...args);
|
|
1561
|
+
return result;
|
|
1562
|
+
}
|
|
1563
|
+
]));
|
|
1564
|
+
return new Proxy({}, trapHandler);
|
|
1565
|
+
}
|
|
1566
|
+
/** Load the module if possible */
|
|
1567
|
+
loadModule() {
|
|
1568
|
+
return requirePackages(this.packageNames);
|
|
1569
|
+
}
|
|
1570
|
+
/** Load the module if possible or throw */
|
|
1571
|
+
loadModuleOrDie() {
|
|
1572
|
+
const module = requirePackages(this.packageNames);
|
|
1573
|
+
if (module) {
|
|
1574
|
+
return module;
|
|
1575
|
+
}
|
|
1576
|
+
throw this.requireError;
|
|
1577
|
+
}
|
|
1578
|
+
get requireError() {
|
|
1579
|
+
const moduleNamePretty = this.moduleName.charAt(0).toUpperCase() + this.moduleName.slice(1);
|
|
1580
|
+
return new Error(`
|
|
1581
|
+
${moduleNamePretty} is missing. :-)
|
|
1582
|
+
|
|
1583
|
+
I've tried loading ${this.packageNames
|
|
1584
|
+
.map(p => `"${p}"`)
|
|
1585
|
+
.join(', ')} - no luck.
|
|
1586
|
+
|
|
1587
|
+
Make sure you install one of those packages or use the named 'addExtra' export,
|
|
1588
|
+
to patch a specific (and maybe non-standard) implementation of ${moduleNamePretty}.
|
|
1589
|
+
|
|
1590
|
+
To get the latest stable version of ${moduleNamePretty} run:
|
|
1591
|
+
'yarn add ${this.moduleName}' or 'npm i ${this.moduleName}'
|
|
1592
|
+
`);
|
|
1593
|
+
}
|
|
1594
|
+
}
|
|
1595
|
+
function requirePackages(packageNames) {
|
|
1596
|
+
for (const name of packageNames) {
|
|
1597
|
+
try {
|
|
1598
|
+
return require(name);
|
|
1599
|
+
}
|
|
1600
|
+
catch (_) {
|
|
1601
|
+
continue; // noop
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
/** Playwright specific module loader */
|
|
1607
|
+
const playwrightLoader = new Loader('playwright', [
|
|
1608
|
+
'playwright-core',
|
|
1609
|
+
'playwright'
|
|
1610
|
+
]);
|
|
1611
|
+
|
|
1612
|
+
const debug = debug$3('playwright-extra:puppeteer-compat');
|
|
1613
|
+
const isPlaywrightPage = (obj) => {
|
|
1614
|
+
return 'unroute' in obj;
|
|
1615
|
+
};
|
|
1616
|
+
const isPlaywrightFrame = (obj) => {
|
|
1617
|
+
return ['parentFrame', 'frameLocator'].every(x => x in obj);
|
|
1618
|
+
};
|
|
1619
|
+
const isPlaywrightBrowser = (obj) => {
|
|
1620
|
+
return 'newContext' in obj;
|
|
1621
|
+
};
|
|
1622
|
+
const isPuppeteerCompat = (obj) => {
|
|
1623
|
+
return !!obj && typeof obj === 'object' && !!obj.isCompatShim;
|
|
1624
|
+
};
|
|
1625
|
+
const cache = {
|
|
1626
|
+
objectToShim: new Map(),
|
|
1627
|
+
cdpSession: {
|
|
1628
|
+
page: new Map(),
|
|
1629
|
+
browser: new Map()
|
|
1630
|
+
}
|
|
1631
|
+
};
|
|
1632
|
+
/** Augment a Playwright object with compatibility with certain Puppeteer methods */
|
|
1633
|
+
function addPuppeteerCompat(object) {
|
|
1634
|
+
if (!object || typeof object !== 'object') {
|
|
1635
|
+
return object;
|
|
1636
|
+
}
|
|
1637
|
+
if (cache.objectToShim.has(object)) {
|
|
1638
|
+
return cache.objectToShim.get(object);
|
|
1639
|
+
}
|
|
1640
|
+
if (isPuppeteerCompat(object)) {
|
|
1641
|
+
return object;
|
|
1642
|
+
}
|
|
1643
|
+
debug('addPuppeteerCompat', cache.objectToShim.size);
|
|
1644
|
+
if (isPlaywrightPage(object) || isPlaywrightFrame(object)) {
|
|
1645
|
+
const shim = createPageShim(object);
|
|
1646
|
+
cache.objectToShim.set(object, shim);
|
|
1647
|
+
return shim;
|
|
1648
|
+
}
|
|
1649
|
+
if (isPlaywrightBrowser(object)) {
|
|
1650
|
+
const shim = createBrowserShim(object);
|
|
1651
|
+
cache.objectToShim.set(object, shim);
|
|
1652
|
+
return shim;
|
|
1653
|
+
}
|
|
1654
|
+
debug('Received unknown object:', Reflect.ownKeys(object));
|
|
1655
|
+
return object;
|
|
1656
|
+
}
|
|
1657
|
+
// Only chromium browsers support CDP
|
|
1658
|
+
const dummyCDPClient = {
|
|
1659
|
+
send: async (...args) => {
|
|
1660
|
+
debug('dummy CDP client called', 'send', args);
|
|
1661
|
+
},
|
|
1662
|
+
on: (...args) => {
|
|
1663
|
+
debug('dummy CDP client called', 'on', args);
|
|
1664
|
+
}
|
|
1665
|
+
};
|
|
1666
|
+
async function getPageCDPSession(page) {
|
|
1667
|
+
let session = cache.cdpSession.page.get(page);
|
|
1668
|
+
if (session) {
|
|
1669
|
+
debug('getPageCDPSession: use existing');
|
|
1670
|
+
return session;
|
|
1671
|
+
}
|
|
1672
|
+
debug('getPageCDPSession: use new');
|
|
1673
|
+
const context = isPlaywrightFrame(page)
|
|
1674
|
+
? page.page().context()
|
|
1675
|
+
: page.context();
|
|
1676
|
+
try {
|
|
1677
|
+
session = await context.newCDPSession(page);
|
|
1678
|
+
cache.cdpSession.page.set(page, session);
|
|
1679
|
+
return session;
|
|
1680
|
+
}
|
|
1681
|
+
catch (err) {
|
|
1682
|
+
debug('getPageCDPSession: error while creating session:', err.message);
|
|
1683
|
+
debug('getPageCDPSession: Unable create CDP session (most likely a different browser than chromium) - returning a dummy');
|
|
1684
|
+
}
|
|
1685
|
+
return dummyCDPClient;
|
|
1686
|
+
}
|
|
1687
|
+
async function getBrowserCDPSession(browser) {
|
|
1688
|
+
let session = cache.cdpSession.browser.get(browser);
|
|
1689
|
+
if (session) {
|
|
1690
|
+
debug('getBrowserCDPSession: use existing');
|
|
1691
|
+
return session;
|
|
1692
|
+
}
|
|
1693
|
+
debug('getBrowserCDPSession: use new');
|
|
1694
|
+
try {
|
|
1695
|
+
session = await browser.newBrowserCDPSession();
|
|
1696
|
+
cache.cdpSession.browser.set(browser, session);
|
|
1697
|
+
return session;
|
|
1698
|
+
}
|
|
1699
|
+
catch (err) {
|
|
1700
|
+
debug('getBrowserCDPSession: error while creating session:', err.message);
|
|
1701
|
+
debug('getBrowserCDPSession: Unable create CDP session (most likely a different browser than chromium) - returning a dummy');
|
|
1702
|
+
}
|
|
1703
|
+
return dummyCDPClient;
|
|
1704
|
+
}
|
|
1705
|
+
function createPageShim(page) {
|
|
1706
|
+
const objId = Math.random().toString(36).substring(2, 7);
|
|
1707
|
+
const shim = new Proxy(page, {
|
|
1708
|
+
get(target, prop) {
|
|
1709
|
+
if (prop === 'isCompatShim' || prop === 'isPlaywright') {
|
|
1710
|
+
return true;
|
|
1711
|
+
}
|
|
1712
|
+
debug('page - get', objId, prop);
|
|
1713
|
+
if (prop === '_client') {
|
|
1714
|
+
return () => ({
|
|
1715
|
+
send: async (method, params) => {
|
|
1716
|
+
const session = await getPageCDPSession(page);
|
|
1717
|
+
return await session.send(method, params);
|
|
1718
|
+
},
|
|
1719
|
+
on: (event, listener) => {
|
|
1720
|
+
getPageCDPSession(page).then(session => {
|
|
1721
|
+
session.on(event, listener);
|
|
1722
|
+
});
|
|
1723
|
+
}
|
|
1724
|
+
});
|
|
1725
|
+
}
|
|
1726
|
+
if (prop === 'setBypassCSP') {
|
|
1727
|
+
return async (enabled) => {
|
|
1728
|
+
const session = await getPageCDPSession(page);
|
|
1729
|
+
return await session.send('Page.setBypassCSP', {
|
|
1730
|
+
enabled
|
|
1731
|
+
});
|
|
1732
|
+
};
|
|
1733
|
+
}
|
|
1734
|
+
if (prop === 'setUserAgent') {
|
|
1735
|
+
return async (userAgent, userAgentMetadata) => {
|
|
1736
|
+
const session = await getPageCDPSession(page);
|
|
1737
|
+
return await session.send('Emulation.setUserAgentOverride', {
|
|
1738
|
+
userAgent,
|
|
1739
|
+
userAgentMetadata
|
|
1740
|
+
});
|
|
1741
|
+
};
|
|
1742
|
+
}
|
|
1743
|
+
if (prop === 'browser') {
|
|
1744
|
+
if (isPlaywrightPage(page)) {
|
|
1745
|
+
return () => {
|
|
1746
|
+
let browser = page.context().browser();
|
|
1747
|
+
if (!browser) {
|
|
1748
|
+
debug('page.browser() - not available, most likely due to launchPersistentContext');
|
|
1749
|
+
// Use a page shim as quick drop-in (so browser.userAgent() still works)
|
|
1750
|
+
browser = page;
|
|
1751
|
+
}
|
|
1752
|
+
return addPuppeteerCompat(browser);
|
|
1753
|
+
};
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
if (prop === 'evaluateOnNewDocument') {
|
|
1757
|
+
if (isPlaywrightPage(page)) {
|
|
1758
|
+
return async function (pageFunction, ...args) {
|
|
1759
|
+
return await page.addInitScript(pageFunction, args[0]);
|
|
1760
|
+
};
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
// Only relevant when page is being used a pseudo stand-in for the browser object (launchPersistentContext)
|
|
1764
|
+
if (prop === 'userAgent') {
|
|
1765
|
+
return async (enabled) => {
|
|
1766
|
+
const session = await getPageCDPSession(page);
|
|
1767
|
+
const data = await session.send('Browser.getVersion');
|
|
1768
|
+
return data.userAgent;
|
|
1769
|
+
};
|
|
1770
|
+
}
|
|
1771
|
+
return Reflect.get(target, prop);
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
return shim;
|
|
1775
|
+
}
|
|
1776
|
+
function createBrowserShim(browser) {
|
|
1777
|
+
const objId = Math.random().toString(36).substring(2, 7);
|
|
1778
|
+
const shim = new Proxy(browser, {
|
|
1779
|
+
get(target, prop) {
|
|
1780
|
+
if (prop === 'isCompatShim' || prop === 'isPlaywright') {
|
|
1781
|
+
return true;
|
|
1782
|
+
}
|
|
1783
|
+
debug('browser - get', objId, prop);
|
|
1784
|
+
if (prop === 'pages') {
|
|
1785
|
+
return () => browser
|
|
1786
|
+
.contexts()
|
|
1787
|
+
.flatMap(c => c.pages().map(page => addPuppeteerCompat(page)));
|
|
1788
|
+
}
|
|
1789
|
+
if (prop === 'userAgent') {
|
|
1790
|
+
return async () => {
|
|
1791
|
+
const session = await getBrowserCDPSession(browser);
|
|
1792
|
+
const data = await session.send('Browser.getVersion');
|
|
1793
|
+
return data.userAgent;
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
return Reflect.get(target, prop);
|
|
1797
|
+
}
|
|
1798
|
+
});
|
|
1799
|
+
return shim;
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
const debug$1 = debug$3('playwright-extra:plugins');
|
|
1803
|
+
class PluginList {
|
|
1804
|
+
constructor() {
|
|
1805
|
+
this._plugins = [];
|
|
1806
|
+
this._dependencyDefaults = new Map();
|
|
1807
|
+
this._dependencyResolution = new Map();
|
|
1808
|
+
}
|
|
1809
|
+
/**
|
|
1810
|
+
* Get a list of all registered plugins.
|
|
1811
|
+
*/
|
|
1812
|
+
get list() {
|
|
1813
|
+
return this._plugins;
|
|
1814
|
+
}
|
|
1815
|
+
/**
|
|
1816
|
+
* Get the names of all registered plugins.
|
|
1817
|
+
*/
|
|
1818
|
+
get names() {
|
|
1819
|
+
return this._plugins.map(p => p.name);
|
|
1820
|
+
}
|
|
1821
|
+
/**
|
|
1822
|
+
* Add a new plugin to the list (after checking if it's well-formed).
|
|
1823
|
+
*
|
|
1824
|
+
* @param plugin
|
|
1825
|
+
* @internal
|
|
1826
|
+
*/
|
|
1827
|
+
add(plugin) {
|
|
1828
|
+
var _a;
|
|
1829
|
+
if (!this.isValidPluginInstance(plugin)) {
|
|
1830
|
+
return false;
|
|
1831
|
+
}
|
|
1832
|
+
if (!!plugin.onPluginRegistered) {
|
|
1833
|
+
plugin.onPluginRegistered({ framework: 'playwright' });
|
|
1834
|
+
}
|
|
1835
|
+
// PuppeteerExtraPlugin: Populate `_childClassMembers` list containing methods defined by the plugin
|
|
1836
|
+
if (!!plugin._registerChildClassMembers) {
|
|
1837
|
+
plugin._registerChildClassMembers(Object.getPrototypeOf(plugin));
|
|
1838
|
+
}
|
|
1839
|
+
if ((_a = plugin.requirements) === null || _a === void 0 ? void 0 : _a.has('dataFromPlugins')) {
|
|
1840
|
+
plugin.getDataFromPlugins = this.getData.bind(this);
|
|
1841
|
+
}
|
|
1842
|
+
this._plugins.push(plugin);
|
|
1843
|
+
return true;
|
|
1844
|
+
}
|
|
1845
|
+
/** Check if the shape of a plugin is correct or warn */
|
|
1846
|
+
isValidPluginInstance(plugin) {
|
|
1847
|
+
if (!plugin ||
|
|
1848
|
+
typeof plugin !== 'object' ||
|
|
1849
|
+
!plugin._isPuppeteerExtraPlugin) {
|
|
1850
|
+
console.error(`Warning: Plugin is not derived from PuppeteerExtraPlugin, ignoring.`, plugin);
|
|
1851
|
+
return false;
|
|
1852
|
+
}
|
|
1853
|
+
if (!plugin.name) {
|
|
1854
|
+
console.error(`Warning: Plugin with no name registering, ignoring.`, plugin);
|
|
1855
|
+
return false;
|
|
1856
|
+
}
|
|
1857
|
+
return true;
|
|
1858
|
+
}
|
|
1859
|
+
/** Error callback in case calling a plugin method throws an error. Can be overwritten. */
|
|
1860
|
+
onPluginError(plugin, method, err) {
|
|
1861
|
+
console.warn(`An error occured while executing "${method}" in plugin "${plugin.name}":`, err);
|
|
1862
|
+
}
|
|
1863
|
+
/**
|
|
1864
|
+
* Define default values for plugins implicitly required through the `dependencies` plugin stanza.
|
|
1865
|
+
*
|
|
1866
|
+
* @param dependencyPath - The string by which the dependency is listed (not the plugin name)
|
|
1867
|
+
*
|
|
1868
|
+
* @example
|
|
1869
|
+
* chromium.use(stealth)
|
|
1870
|
+
* chromium.plugins.setDependencyDefaults('stealth/evasions/webgl.vendor', { vendor: 'Bob', renderer: 'Alice' })
|
|
1871
|
+
*/
|
|
1872
|
+
setDependencyDefaults(dependencyPath, opts) {
|
|
1873
|
+
this._dependencyDefaults.set(dependencyPath, opts);
|
|
1874
|
+
return this;
|
|
1875
|
+
}
|
|
1876
|
+
/**
|
|
1877
|
+
* Define custom plugin modules for plugins implicitly required through the `dependencies` plugin stanza.
|
|
1878
|
+
*
|
|
1879
|
+
* Using this will prevent dynamic imports from being used, which JS bundlers often have issues with.
|
|
1880
|
+
*
|
|
1881
|
+
* @example
|
|
1882
|
+
* chromium.use(stealth)
|
|
1883
|
+
* chromium.plugins.setDependencyResolution('stealth/evasions/webgl.vendor', VendorPlugin)
|
|
1884
|
+
*/
|
|
1885
|
+
setDependencyResolution(dependencyPath, pluginModule) {
|
|
1886
|
+
this._dependencyResolution.set(dependencyPath, pluginModule);
|
|
1887
|
+
return this;
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Prepare plugins to be used (resolve dependencies, ordering)
|
|
1891
|
+
* @internal
|
|
1892
|
+
*/
|
|
1893
|
+
prepare() {
|
|
1894
|
+
this.resolveDependencies();
|
|
1895
|
+
this.order();
|
|
1896
|
+
}
|
|
1897
|
+
/** Return all plugins using the supplied method */
|
|
1898
|
+
filterByMethod(methodName) {
|
|
1899
|
+
return this._plugins.filter(plugin => {
|
|
1900
|
+
// PuppeteerExtraPlugin: The base class will already define all methods, hence we need to do a different check
|
|
1901
|
+
if (!!plugin._childClassMembers &&
|
|
1902
|
+
Array.isArray(plugin._childClassMembers)) {
|
|
1903
|
+
return plugin._childClassMembers.includes(methodName);
|
|
1904
|
+
}
|
|
1905
|
+
return methodName in plugin;
|
|
1906
|
+
});
|
|
1907
|
+
}
|
|
1908
|
+
/** Conditionally add puppeteer compatibility to values provided to the plugins */
|
|
1909
|
+
_addPuppeteerCompatIfNeeded(plugin, method, args) {
|
|
1910
|
+
const canUseShim = plugin._isPuppeteerExtraPlugin && !plugin.noPuppeteerShim;
|
|
1911
|
+
const methodWhitelist = [
|
|
1912
|
+
'onBrowser',
|
|
1913
|
+
'onPageCreated',
|
|
1914
|
+
'onPageClose',
|
|
1915
|
+
'afterConnect',
|
|
1916
|
+
'afterLaunch'
|
|
1917
|
+
];
|
|
1918
|
+
const shouldUseShim = methodWhitelist.includes(method);
|
|
1919
|
+
if (!canUseShim || !shouldUseShim) {
|
|
1920
|
+
return args;
|
|
1921
|
+
}
|
|
1922
|
+
debug$1('add puppeteer compatibility', plugin.name, method);
|
|
1923
|
+
return [...args.map(arg => addPuppeteerCompat(arg))];
|
|
1924
|
+
}
|
|
1925
|
+
/**
|
|
1926
|
+
* Dispatch plugin lifecycle events in a typesafe way.
|
|
1927
|
+
* Only Plugins that expose the supplied property will be called.
|
|
1928
|
+
*
|
|
1929
|
+
* Will not await results to dispatch events as fast as possible to all plugins.
|
|
1930
|
+
*
|
|
1931
|
+
* @param method - The lifecycle method name
|
|
1932
|
+
* @param args - Optional: Any arguments to be supplied to the plugin methods
|
|
1933
|
+
* @internal
|
|
1934
|
+
*/
|
|
1935
|
+
dispatch(method, ...args) {
|
|
1936
|
+
var _a, _b;
|
|
1937
|
+
const plugins = this.filterByMethod(method);
|
|
1938
|
+
debug$1('dispatch', method, {
|
|
1939
|
+
all: this._plugins.length,
|
|
1940
|
+
filteredByMethod: plugins.length
|
|
1941
|
+
});
|
|
1942
|
+
for (const plugin of plugins) {
|
|
1943
|
+
try {
|
|
1944
|
+
args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
|
|
1945
|
+
const fnType = (_b = (_a = plugin[method]) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name;
|
|
1946
|
+
debug$1('dispatch to plugin', {
|
|
1947
|
+
plugin: plugin.name,
|
|
1948
|
+
method,
|
|
1949
|
+
fnType
|
|
1950
|
+
});
|
|
1951
|
+
if (fnType === 'AsyncFunction') {
|
|
1952
|
+
;
|
|
1953
|
+
plugin[method](...args).catch((err) => this.onPluginError(plugin, method, err));
|
|
1954
|
+
}
|
|
1955
|
+
else {
|
|
1956
|
+
;
|
|
1957
|
+
plugin[method](...args);
|
|
1958
|
+
}
|
|
1959
|
+
}
|
|
1960
|
+
catch (err) {
|
|
1961
|
+
this.onPluginError(plugin, method, err);
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Dispatch plugin lifecycle events in a typesafe way.
|
|
1967
|
+
* Only Plugins that expose the supplied property will be called.
|
|
1968
|
+
*
|
|
1969
|
+
* Can also be used to get a definite return value after passing it to plugins:
|
|
1970
|
+
* Calls plugins sequentially and passes on a value (waterfall style).
|
|
1971
|
+
*
|
|
1972
|
+
* The plugins can either modify the value or return an updated one.
|
|
1973
|
+
* Will return the latest, updated value which ran through all plugins.
|
|
1974
|
+
*
|
|
1975
|
+
* By convention only the first argument will be used as the updated value.
|
|
1976
|
+
*
|
|
1977
|
+
* @param method - The lifecycle method name
|
|
1978
|
+
* @param args - Optional: Any arguments to be supplied to the plugin methods
|
|
1979
|
+
* @internal
|
|
1980
|
+
*/
|
|
1981
|
+
async dispatchBlocking(method, ...args) {
|
|
1982
|
+
const plugins = this.filterByMethod(method);
|
|
1983
|
+
debug$1('dispatchBlocking', method, {
|
|
1984
|
+
all: this._plugins.length,
|
|
1985
|
+
filteredByMethod: plugins.length
|
|
1986
|
+
});
|
|
1987
|
+
let retValue = null;
|
|
1988
|
+
for (const plugin of plugins) {
|
|
1989
|
+
try {
|
|
1990
|
+
args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
|
|
1991
|
+
retValue = await plugin[method](...args);
|
|
1992
|
+
// In case we got a return value use that as new first argument for followup function calls
|
|
1993
|
+
if (retValue !== undefined) {
|
|
1994
|
+
args[0] = retValue;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
catch (err) {
|
|
1998
|
+
this.onPluginError(plugin, method, err);
|
|
1999
|
+
return retValue;
|
|
2000
|
+
}
|
|
2001
|
+
}
|
|
2002
|
+
return retValue;
|
|
2003
|
+
}
|
|
2004
|
+
/**
|
|
2005
|
+
* Order plugins that have expressed a special placement requirement.
|
|
2006
|
+
*
|
|
2007
|
+
* This is useful/necessary for e.g. plugins that depend on the data from other plugins.
|
|
2008
|
+
*
|
|
2009
|
+
* @private
|
|
2010
|
+
*/
|
|
2011
|
+
order() {
|
|
2012
|
+
debug$1('order:before', this.names);
|
|
2013
|
+
const runLast = this._plugins
|
|
2014
|
+
.filter(p => { var _a; return (_a = p.requirements) === null || _a === void 0 ? void 0 : _a.has('runLast'); })
|
|
2015
|
+
.map(p => p.name);
|
|
2016
|
+
for (const name of runLast) {
|
|
2017
|
+
const index = this._plugins.findIndex(p => p.name === name);
|
|
2018
|
+
this._plugins.push(this._plugins.splice(index, 1)[0]);
|
|
2019
|
+
}
|
|
2020
|
+
debug$1('order:after', this.names);
|
|
2021
|
+
}
|
|
2022
|
+
/**
|
|
2023
|
+
* Collects the exposed `data` property of all registered plugins.
|
|
2024
|
+
* Will be reduced/flattened to a single array.
|
|
2025
|
+
*
|
|
2026
|
+
* Can be accessed by plugins that listed the `dataFromPlugins` requirement.
|
|
2027
|
+
*
|
|
2028
|
+
* Implemented mainly for plugins that need data from other plugins (e.g. `user-preferences`).
|
|
2029
|
+
*
|
|
2030
|
+
* @see [PuppeteerExtraPlugin]/data
|
|
2031
|
+
* @param name - Filter data by optional name
|
|
2032
|
+
*
|
|
2033
|
+
* @private
|
|
2034
|
+
*/
|
|
2035
|
+
getData(name) {
|
|
2036
|
+
const data = this._plugins
|
|
2037
|
+
.filter((p) => !!p.data)
|
|
2038
|
+
.map((p) => (Array.isArray(p.data) ? p.data : [p.data]))
|
|
2039
|
+
.reduce((acc, arr) => [...acc, ...arr], []);
|
|
2040
|
+
return name ? data.filter((d) => d.name === name) : data;
|
|
2041
|
+
}
|
|
2042
|
+
/**
|
|
2043
|
+
* Handle `plugins` stanza (already instantiated plugins that don't require dynamic imports)
|
|
2044
|
+
*/
|
|
2045
|
+
resolvePluginsStanza() {
|
|
2046
|
+
debug$1('resolvePluginsStanza');
|
|
2047
|
+
const pluginNames = new Set(this.names);
|
|
2048
|
+
this._plugins
|
|
2049
|
+
.filter(p => !!p.plugins && p.plugins.length)
|
|
2050
|
+
.filter(p => !pluginNames.has(p.name)) // TBD: Do we want to filter out existing?
|
|
2051
|
+
.forEach(parent => {
|
|
2052
|
+
(parent.plugins || []).forEach(p => {
|
|
2053
|
+
debug$1(parent.name, 'adding missing plugin', p.name);
|
|
2054
|
+
this.add(p);
|
|
2055
|
+
});
|
|
2056
|
+
});
|
|
2057
|
+
}
|
|
2058
|
+
/**
|
|
2059
|
+
* Handle `dependencies` stanza (which requires dynamic imports)
|
|
2060
|
+
*
|
|
2061
|
+
* Plugins can define `dependencies` as a Set or Array of dependency paths, or a Map with additional opts
|
|
2062
|
+
*
|
|
2063
|
+
* @note
|
|
2064
|
+
* - The default opts for implicit dependencies can be defined using `setDependencyDefaults()`
|
|
2065
|
+
* - Dynamic imports can be avoided by providing plugin modules with `setDependencyResolution()`
|
|
2066
|
+
*/
|
|
2067
|
+
resolveDependenciesStanza() {
|
|
2068
|
+
debug$1('resolveDependenciesStanza');
|
|
2069
|
+
/** Attempt to dynamically require a plugin module */
|
|
2070
|
+
const requireDependencyOrDie = (parentName, dependencyPath) => {
|
|
2071
|
+
// If the user provided the plugin module already we use that
|
|
2072
|
+
if (this._dependencyResolution.has(dependencyPath)) {
|
|
2073
|
+
return this._dependencyResolution.get(dependencyPath);
|
|
2074
|
+
}
|
|
2075
|
+
const possiblePrefixes = ['puppeteer-extra-plugin-']; // could be extended later
|
|
2076
|
+
const isAlreadyPrefixed = possiblePrefixes.some(prefix => dependencyPath.startsWith(prefix));
|
|
2077
|
+
const packagePaths = [];
|
|
2078
|
+
// If the dependency is not already prefixed we attempt to require all possible combinations to find one that works
|
|
2079
|
+
if (!isAlreadyPrefixed) {
|
|
2080
|
+
packagePaths.push(...possiblePrefixes.map(prefix => prefix + dependencyPath));
|
|
2081
|
+
}
|
|
2082
|
+
// We always attempt to require the path verbatim (as a last resort)
|
|
2083
|
+
packagePaths.push(dependencyPath);
|
|
2084
|
+
const pluginModule = requirePackages(packagePaths);
|
|
2085
|
+
if (pluginModule) {
|
|
2086
|
+
return pluginModule;
|
|
2087
|
+
}
|
|
2088
|
+
const explanation = `
|
|
2089
|
+
The plugin '${parentName}' listed '${dependencyPath}' as dependency,
|
|
2090
|
+
which could not be found. Please install it:
|
|
2091
|
+
|
|
2092
|
+
${packagePaths
|
|
2093
|
+
.map(packagePath => `yarn add ${packagePath.split('/')[0]}`)
|
|
2094
|
+
.join(`\n or:\n`)}
|
|
2095
|
+
|
|
2096
|
+
Note: You don't need to require the plugin yourself,
|
|
2097
|
+
unless you want to modify it's default settings.
|
|
2098
|
+
|
|
2099
|
+
If your bundler has issues with dynamic imports take a look at '.plugins.setDependencyResolution()'.
|
|
2100
|
+
`;
|
|
2101
|
+
console.warn(explanation);
|
|
2102
|
+
throw new Error('Plugin dependency not found');
|
|
2103
|
+
};
|
|
2104
|
+
const existingPluginNames = new Set(this.names);
|
|
2105
|
+
const recursivelyLoadMissingDependencies = ({ name: parentName, dependencies }) => {
|
|
2106
|
+
if (!dependencies) {
|
|
2107
|
+
return;
|
|
2108
|
+
}
|
|
2109
|
+
const processDependency = (dependencyPath, opts) => {
|
|
2110
|
+
const pluginModule = requireDependencyOrDie(parentName, dependencyPath);
|
|
2111
|
+
opts = opts || this._dependencyDefaults.get(dependencyPath) || {};
|
|
2112
|
+
const plugin = pluginModule(opts);
|
|
2113
|
+
if (existingPluginNames.has(plugin.name)) {
|
|
2114
|
+
debug$1(parentName, '=> dependency already exists:', plugin.name);
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
existingPluginNames.add(plugin.name);
|
|
2118
|
+
debug$1(parentName, '=> adding new dependency:', plugin.name, opts);
|
|
2119
|
+
this.add(plugin);
|
|
2120
|
+
return recursivelyLoadMissingDependencies(plugin);
|
|
2121
|
+
};
|
|
2122
|
+
if (dependencies instanceof Set || Array.isArray(dependencies)) {
|
|
2123
|
+
return [...dependencies].forEach(dependencyPath => processDependency(dependencyPath));
|
|
2124
|
+
}
|
|
2125
|
+
if (dependencies instanceof Map) {
|
|
2126
|
+
// Note: `k,v => v,k` (Map + forEach will reverse the order)
|
|
2127
|
+
return dependencies.forEach((v, k) => processDependency(k, v));
|
|
2128
|
+
}
|
|
2129
|
+
};
|
|
2130
|
+
this.list.forEach(recursivelyLoadMissingDependencies);
|
|
2131
|
+
}
|
|
2132
|
+
/**
|
|
2133
|
+
* Lightweight plugin dependency management to require plugins and code mods on demand.
|
|
2134
|
+
* @private
|
|
2135
|
+
*/
|
|
2136
|
+
resolveDependencies() {
|
|
2137
|
+
debug$1('resolveDependencies');
|
|
2138
|
+
this.resolvePluginsStanza();
|
|
2139
|
+
this.resolveDependenciesStanza();
|
|
2140
|
+
}
|
|
2141
|
+
}
|
|
2142
|
+
|
|
2143
|
+
const debug$2 = debug$3('playwright-extra');
|
|
2144
|
+
/**
|
|
2145
|
+
* Modular plugin framework to teach `playwright` new tricks.
|
|
2146
|
+
*/
|
|
2147
|
+
class PlaywrightExtraClass {
|
|
2148
|
+
constructor(_launcher) {
|
|
2149
|
+
this._launcher = _launcher;
|
|
2150
|
+
this.plugins = new PluginList();
|
|
2151
|
+
}
|
|
2152
|
+
/**
|
|
2153
|
+
* The **main interface** to register plugins.
|
|
2154
|
+
*
|
|
2155
|
+
* Can be called multiple times to enable multiple plugins.
|
|
2156
|
+
*
|
|
2157
|
+
* Plugins derived from `PuppeteerExtraPlugin` will be used with a compatiblity layer.
|
|
2158
|
+
*
|
|
2159
|
+
* @example
|
|
2160
|
+
* chromium.use(plugin1).use(plugin2)
|
|
2161
|
+
* firefox.use(plugin1).use(plugin2)
|
|
2162
|
+
*
|
|
2163
|
+
* @see [PuppeteerExtraPlugin]
|
|
2164
|
+
*
|
|
2165
|
+
* @return The same `PlaywrightExtra` instance (for optional chaining)
|
|
2166
|
+
*/
|
|
2167
|
+
use(plugin) {
|
|
2168
|
+
const isValid = plugin && 'name' in plugin;
|
|
2169
|
+
if (!isValid) {
|
|
2170
|
+
throw new Error('A plugin must be provided to .use()');
|
|
2171
|
+
}
|
|
2172
|
+
if (this.plugins.add(plugin)) {
|
|
2173
|
+
debug$2('Plugin registered', plugin.name);
|
|
2174
|
+
}
|
|
2175
|
+
return this;
|
|
2176
|
+
}
|
|
2177
|
+
/**
|
|
2178
|
+
* In order to support a default export which will require vanilla playwright automatically,
|
|
2179
|
+
* as well as `addExtra` to patch a provided launcher, we need to so some gymnastics here.
|
|
2180
|
+
*
|
|
2181
|
+
* Otherwise this would throw immediately, even when only using the `addExtra` export with an arbitrary compatible launcher.
|
|
2182
|
+
*
|
|
2183
|
+
* The solution is to make the vanilla launcher optional and only throw once we try to effectively use and can't find it.
|
|
2184
|
+
*
|
|
2185
|
+
* @internal
|
|
2186
|
+
*/
|
|
2187
|
+
get launcher() {
|
|
2188
|
+
if (!this._launcher) {
|
|
2189
|
+
throw playwrightLoader.requireError;
|
|
2190
|
+
}
|
|
2191
|
+
return this._launcher;
|
|
2192
|
+
}
|
|
2193
|
+
async launch(...args) {
|
|
2194
|
+
if (!this.launcher.launch) {
|
|
2195
|
+
throw new Error('Launcher does not support "launch"');
|
|
2196
|
+
}
|
|
2197
|
+
let [options] = args;
|
|
2198
|
+
options = Object.assign({ args: [] }, (options || {})); // Initialize args array
|
|
2199
|
+
debug$2('launch', options);
|
|
2200
|
+
this.plugins.prepare();
|
|
2201
|
+
// Give plugins the chance to modify the options before continuing
|
|
2202
|
+
options =
|
|
2203
|
+
(await this.plugins.dispatchBlocking('beforeLaunch', options)) || options;
|
|
2204
|
+
debug$2('launch with options', options);
|
|
2205
|
+
if ('userDataDir' in options) {
|
|
2206
|
+
debug$2("A plugin defined userDataDir during .launch, which isn't supported by playwright - ignoring");
|
|
2207
|
+
delete options.userDataDir;
|
|
2208
|
+
}
|
|
2209
|
+
const browser = await this.launcher['launch'](options);
|
|
2210
|
+
await this.plugins.dispatchBlocking('onBrowser', browser);
|
|
2211
|
+
await this._bindBrowserEvents(browser);
|
|
2212
|
+
await this.plugins.dispatchBlocking('afterLaunch', browser);
|
|
2213
|
+
return browser;
|
|
2214
|
+
}
|
|
2215
|
+
async launchPersistentContext(...args) {
|
|
2216
|
+
if (!this.launcher.launchPersistentContext) {
|
|
2217
|
+
throw new Error('Launcher does not support "launchPersistentContext"');
|
|
2218
|
+
}
|
|
2219
|
+
let [userDataDir, options] = args;
|
|
2220
|
+
options = Object.assign({ args: [] }, (options || {})); // Initialize args array
|
|
2221
|
+
debug$2('launchPersistentContext', options);
|
|
2222
|
+
this.plugins.prepare();
|
|
2223
|
+
// Give plugins the chance to modify the options before continuing
|
|
2224
|
+
options =
|
|
2225
|
+
(await this.plugins.dispatchBlocking('beforeLaunch', options)) || options;
|
|
2226
|
+
const context = await this.launcher['launchPersistentContext'](userDataDir, options);
|
|
2227
|
+
await this.plugins.dispatchBlocking('afterLaunch', context);
|
|
2228
|
+
this._bindBrowserContextEvents(context);
|
|
2229
|
+
return context;
|
|
2230
|
+
}
|
|
2231
|
+
async connect(wsEndpointOrOptions, wsOptions = {}) {
|
|
2232
|
+
if (!this.launcher.connect) {
|
|
2233
|
+
throw new Error('Launcher does not support "connect"');
|
|
2234
|
+
}
|
|
2235
|
+
this.plugins.prepare();
|
|
2236
|
+
// Playwright currently supports two function signatures for .connect
|
|
2237
|
+
let options = {};
|
|
2238
|
+
let wsEndpointAsString = false;
|
|
2239
|
+
if (typeof wsEndpointOrOptions === 'object') {
|
|
2240
|
+
options = Object.assign(Object.assign({}, wsEndpointOrOptions), wsOptions);
|
|
2241
|
+
}
|
|
2242
|
+
else {
|
|
2243
|
+
wsEndpointAsString = true;
|
|
2244
|
+
options = Object.assign({ wsEndpoint: wsEndpointOrOptions }, wsOptions);
|
|
2245
|
+
}
|
|
2246
|
+
debug$2('connect', options);
|
|
2247
|
+
// Give plugins the chance to modify the options before launch/connect
|
|
2248
|
+
options =
|
|
2249
|
+
(await this.plugins.dispatchBlocking('beforeConnect', options)) || options;
|
|
2250
|
+
// Follow call signature of end user
|
|
2251
|
+
const args = [];
|
|
2252
|
+
const wsEndpoint = options.wsEndpoint;
|
|
2253
|
+
if (wsEndpointAsString) {
|
|
2254
|
+
delete options.wsEndpoint;
|
|
2255
|
+
args.push(wsEndpoint, options);
|
|
2256
|
+
}
|
|
2257
|
+
else {
|
|
2258
|
+
args.push(options);
|
|
2259
|
+
}
|
|
2260
|
+
const browser = (await this.launcher['connect'](...args));
|
|
2261
|
+
await this.plugins.dispatchBlocking('onBrowser', browser);
|
|
2262
|
+
await this._bindBrowserEvents(browser);
|
|
2263
|
+
await this.plugins.dispatchBlocking('afterConnect', browser);
|
|
2264
|
+
return browser;
|
|
2265
|
+
}
|
|
2266
|
+
async connectOverCDP(wsEndpointOrOptions, wsOptions = {}) {
|
|
2267
|
+
if (!this.launcher.connectOverCDP) {
|
|
2268
|
+
throw new Error(`Launcher does not implement 'connectOverCDP'`);
|
|
2269
|
+
}
|
|
2270
|
+
this.plugins.prepare();
|
|
2271
|
+
// Playwright currently supports two function signatures for .connectOverCDP
|
|
2272
|
+
let options = {};
|
|
2273
|
+
let wsEndpointAsString = false;
|
|
2274
|
+
if (typeof wsEndpointOrOptions === 'object') {
|
|
2275
|
+
options = Object.assign(Object.assign({}, wsEndpointOrOptions), wsOptions);
|
|
2276
|
+
}
|
|
2277
|
+
else {
|
|
2278
|
+
wsEndpointAsString = true;
|
|
2279
|
+
options = Object.assign({ endpointURL: wsEndpointOrOptions }, wsOptions);
|
|
2280
|
+
}
|
|
2281
|
+
debug$2('connectOverCDP');
|
|
2282
|
+
// Give plugins the chance to modify the options before launch/connect
|
|
2283
|
+
options =
|
|
2284
|
+
(await this.plugins.dispatchBlocking('beforeConnect', options)) || options;
|
|
2285
|
+
// Follow call signature of end user
|
|
2286
|
+
const args = [];
|
|
2287
|
+
const endpointURL = options.endpointURL;
|
|
2288
|
+
if (wsEndpointAsString) {
|
|
2289
|
+
delete options.endpointURL;
|
|
2290
|
+
args.push(endpointURL, options);
|
|
2291
|
+
}
|
|
2292
|
+
else {
|
|
2293
|
+
args.push(options);
|
|
2294
|
+
}
|
|
2295
|
+
const browser = (await this.launcher['connectOverCDP'](...args));
|
|
2296
|
+
await this.plugins.dispatchBlocking('onBrowser', browser);
|
|
2297
|
+
await this._bindBrowserEvents(browser);
|
|
2298
|
+
await this.plugins.dispatchBlocking('afterConnect', browser);
|
|
2299
|
+
return browser;
|
|
2300
|
+
}
|
|
2301
|
+
async _bindBrowserContextEvents(context, contextOptions) {
|
|
2302
|
+
debug$2('_bindBrowserContextEvents');
|
|
2303
|
+
this.plugins.dispatch('onContextCreated', context, contextOptions);
|
|
2304
|
+
// Make sure things like `addInitScript` show an effect on the very first page as well
|
|
2305
|
+
context.newPage = ((originalMethod, ctx) => {
|
|
2306
|
+
return async () => {
|
|
2307
|
+
const page = await originalMethod.call(ctx);
|
|
2308
|
+
await page.goto('about:blank');
|
|
2309
|
+
return page;
|
|
2310
|
+
};
|
|
2311
|
+
})(context.newPage, context);
|
|
2312
|
+
context.on('close', () => {
|
|
2313
|
+
// When using `launchPersistentContext` context closing is the same as browser closing
|
|
2314
|
+
if (!context.browser()) {
|
|
2315
|
+
this.plugins.dispatch('onDisconnected');
|
|
2316
|
+
}
|
|
2317
|
+
});
|
|
2318
|
+
context.on('page', page => {
|
|
2319
|
+
this.plugins.dispatch('onPageCreated', page);
|
|
2320
|
+
page.on('close', () => {
|
|
2321
|
+
this.plugins.dispatch('onPageClose', page);
|
|
2322
|
+
});
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
async _bindBrowserEvents(browser) {
|
|
2326
|
+
debug$2('_bindPlaywrightBrowserEvents');
|
|
2327
|
+
browser.on('disconnected', () => {
|
|
2328
|
+
this.plugins.dispatch('onDisconnected', browser);
|
|
2329
|
+
});
|
|
2330
|
+
// Note: `browser.newPage` will implicitly call `browser.newContext` as well
|
|
2331
|
+
browser.newContext = ((originalMethod, ctx) => {
|
|
2332
|
+
return async (options = {}) => {
|
|
2333
|
+
const contextOptions = (await this.plugins.dispatchBlocking('beforeContext', options, browser)) || options;
|
|
2334
|
+
const context = await originalMethod.call(ctx, contextOptions);
|
|
2335
|
+
this._bindBrowserContextEvents(context, contextOptions);
|
|
2336
|
+
return context;
|
|
2337
|
+
};
|
|
2338
|
+
})(browser.newContext, browser);
|
|
2339
|
+
}
|
|
2340
|
+
}
|
|
2341
|
+
/**
|
|
2342
|
+
* PlaywrightExtra class with additional launcher methods.
|
|
2343
|
+
*
|
|
2344
|
+
* Augments the class with an instance proxy to pass on methods that are not augmented to the original target.
|
|
2345
|
+
*
|
|
2346
|
+
*/
|
|
2347
|
+
const PlaywrightExtra = new Proxy(PlaywrightExtraClass, {
|
|
2348
|
+
construct(classTarget, args) {
|
|
2349
|
+
debug$2(`create instance of ${classTarget.name}`);
|
|
2350
|
+
const result = Reflect.construct(classTarget, args);
|
|
2351
|
+
return new Proxy(result, {
|
|
2352
|
+
get(target, prop) {
|
|
2353
|
+
if (prop in target) {
|
|
2354
|
+
return Reflect.get(target, prop);
|
|
2355
|
+
}
|
|
2356
|
+
debug$2('proxying property to original launcher: ', prop);
|
|
2357
|
+
return Reflect.get(target.launcher, prop);
|
|
2358
|
+
}
|
|
2359
|
+
});
|
|
2360
|
+
}
|
|
2361
|
+
});
|
|
2362
|
+
|
|
2363
|
+
/**
|
|
2364
|
+
* Augment the provided Playwright browser launcher with plugin functionality.
|
|
2365
|
+
*
|
|
2366
|
+
* Using `addExtra` will always create a fresh PlaywrightExtra instance.
|
|
2367
|
+
*
|
|
2368
|
+
* @example
|
|
2369
|
+
* import playwright from 'playwright'
|
|
2370
|
+
* import { addExtra } from 'playwright-extra'
|
|
2371
|
+
*
|
|
2372
|
+
* const chromium = addExtra(playwright.chromium)
|
|
2373
|
+
* chromium.use(plugin)
|
|
2374
|
+
*
|
|
2375
|
+
* @param launcher - Playwright (or compatible) browser launcher
|
|
2376
|
+
*/
|
|
2377
|
+
const addExtra = (launcher) => new PlaywrightExtra(launcher);
|
|
2378
|
+
/**
|
|
2379
|
+
* This object can be used to launch or connect to Chromium with plugin functionality.
|
|
2380
|
+
*
|
|
2381
|
+
* This default export will behave exactly the same as the regular playwright
|
|
2382
|
+
* (just with extra plugin functionality) and can be used as a drop-in replacement.
|
|
2383
|
+
*
|
|
2384
|
+
* Behind the scenes it will try to require either the `playwright-core`
|
|
2385
|
+
* or `playwright` module from the installed dependencies.
|
|
2386
|
+
*
|
|
2387
|
+
* @note
|
|
2388
|
+
* Due to Node.js import caching this will result in a single
|
|
2389
|
+
* PlaywrightExtra instance, even when used in different files. If you need multiple
|
|
2390
|
+
* instances with different plugins please use `addExtra`.
|
|
2391
|
+
*
|
|
2392
|
+
* @example
|
|
2393
|
+
* // javascript import
|
|
2394
|
+
* const { chromium } = require('playwright-extra')
|
|
2395
|
+
*
|
|
2396
|
+
* // typescript/es6 module import
|
|
2397
|
+
* import { chromium } from 'playwright-extra'
|
|
2398
|
+
*
|
|
2399
|
+
* // Add plugins
|
|
2400
|
+
* chromium.use(...)
|
|
2401
|
+
*/
|
|
2402
|
+
const chromium = addExtra((playwrightLoader.loadModule() || {}).chromium);
|
|
2403
|
+
/**
|
|
2404
|
+
* This object can be used to launch or connect to Firefox with plugin functionality
|
|
2405
|
+
* @note This export will always return the same instance, if you wish to use multiple instances with different plugins use `addExtra`
|
|
2406
|
+
*/
|
|
2407
|
+
addExtra((playwrightLoader.loadModule() || {}).firefox);
|
|
2408
|
+
/**
|
|
2409
|
+
* This object can be used to launch or connect to Webkit with plugin functionality
|
|
2410
|
+
* @note This export will always return the same instance, if you wish to use multiple instances with different plugins use `addExtra`
|
|
2411
|
+
*/
|
|
2412
|
+
addExtra((playwrightLoader.loadModule() || {}).webkit);
|
|
2413
|
+
// Other playwright module exports we simply re-export with lazy loading
|
|
2414
|
+
playwrightLoader.lazyloadExportOrDie('_android');
|
|
2415
|
+
playwrightLoader.lazyloadExportOrDie('_electron');
|
|
2416
|
+
playwrightLoader.lazyloadExportOrDie('request');
|
|
2417
|
+
playwrightLoader.lazyloadExportOrDie('selectors');
|
|
2418
|
+
playwrightLoader.lazyloadExportOrDie('devices');
|
|
2419
|
+
playwrightLoader.lazyloadExportOrDie('errors');
|
|
2420
|
+
|
|
2421
|
+
/*!
|
|
2422
|
+
* puppeteer-extra-plugin v3.2.2 by berstend
|
|
2423
|
+
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin
|
|
2424
|
+
* @license MIT
|
|
2425
|
+
*/
|
|
2426
|
+
|
|
2427
|
+
/** @private */
|
|
2428
|
+
const merge$1 = require('merge-deep');
|
|
2429
|
+
/**
|
|
2430
|
+
* Base class for `puppeteer-extra` plugins.
|
|
2431
|
+
*
|
|
2432
|
+
* Provides convenience methods to avoid boilerplate.
|
|
2433
|
+
*
|
|
2434
|
+
* All common `puppeteer` browser events will be bound to
|
|
2435
|
+
* the plugin instance, if a respectively named class member is found.
|
|
2436
|
+
*
|
|
2437
|
+
* Please refer to the [puppeteer API documentation](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md) as well.
|
|
2438
|
+
*
|
|
2439
|
+
* @example
|
|
2440
|
+
* // hello-world-plugin.js
|
|
2441
|
+
* const { PuppeteerExtraPlugin } = require('puppeteer-extra-plugin')
|
|
2442
|
+
*
|
|
2443
|
+
* class Plugin extends PuppeteerExtraPlugin {
|
|
2444
|
+
* constructor (opts = { }) { super(opts) }
|
|
2445
|
+
*
|
|
2446
|
+
* get name () { return 'hello-world' }
|
|
2447
|
+
*
|
|
2448
|
+
* async onPageCreated (page) {
|
|
2449
|
+
* this.debug('page created', page.url())
|
|
2450
|
+
* const ua = await page.browser().userAgent()
|
|
2451
|
+
* this.debug('user agent', ua)
|
|
2452
|
+
* }
|
|
2453
|
+
* }
|
|
2454
|
+
*
|
|
2455
|
+
* module.exports = function (pluginConfig) { return new Plugin(pluginConfig) }
|
|
2456
|
+
*
|
|
2457
|
+
*
|
|
2458
|
+
* // foo.js
|
|
2459
|
+
* const puppeteer = require('puppeteer-extra')
|
|
2460
|
+
* puppeteer.use(require('./hello-world-plugin')())
|
|
2461
|
+
*
|
|
2462
|
+
* ;(async () => {
|
|
2463
|
+
* const browser = await puppeteer.launch({headless: false})
|
|
2464
|
+
* const page = await browser.newPage()
|
|
2465
|
+
* await page.goto('http://example.com', {waitUntil: 'domcontentloaded'})
|
|
2466
|
+
* await browser.close()
|
|
2467
|
+
* })()
|
|
2468
|
+
*
|
|
2469
|
+
*/
|
|
2470
|
+
class PuppeteerExtraPlugin$1 {
|
|
2471
|
+
constructor(opts) {
|
|
2472
|
+
this._debugBase = debug$3(`puppeteer-extra-plugin:base:${this.name}`);
|
|
2473
|
+
this._childClassMembers = [];
|
|
2474
|
+
this._opts = merge$1(this.defaults, opts || {});
|
|
2475
|
+
this._debugBase('Initialized.');
|
|
2476
|
+
}
|
|
2477
|
+
/**
|
|
2478
|
+
* Plugin name (required).
|
|
2479
|
+
*
|
|
2480
|
+
* Convention:
|
|
2481
|
+
* - Package: `puppeteer-extra-plugin-anonymize-ua`
|
|
2482
|
+
* - Name: `anonymize-ua`
|
|
2483
|
+
*
|
|
2484
|
+
* @example
|
|
2485
|
+
* get name () { return 'anonymize-ua' }
|
|
2486
|
+
*/
|
|
2487
|
+
get name() {
|
|
2488
|
+
throw new Error('Plugin must override "name"');
|
|
2489
|
+
}
|
|
2490
|
+
/**
|
|
2491
|
+
* Plugin defaults (optional).
|
|
2492
|
+
*
|
|
2493
|
+
* If defined will be ([deep-](https://github.com/jonschlinkert/merge-deep))merged with the (optional) user supplied options (supplied during plugin instantiation).
|
|
2494
|
+
*
|
|
2495
|
+
* The result of merging defaults with user supplied options can be accessed through `this.opts`.
|
|
2496
|
+
*
|
|
2497
|
+
* @see [[opts]]
|
|
2498
|
+
*
|
|
2499
|
+
* @example
|
|
2500
|
+
* get defaults () {
|
|
2501
|
+
* return {
|
|
2502
|
+
* stripHeadless: true,
|
|
2503
|
+
* makeWindows: true,
|
|
2504
|
+
* customFn: null
|
|
2505
|
+
* }
|
|
2506
|
+
* }
|
|
2507
|
+
*
|
|
2508
|
+
* // Users can overwrite plugin defaults during instantiation:
|
|
2509
|
+
* puppeteer.use(require('puppeteer-extra-plugin-foobar')({ makeWindows: false }))
|
|
2510
|
+
*/
|
|
2511
|
+
get defaults() {
|
|
2512
|
+
return {};
|
|
2513
|
+
}
|
|
2514
|
+
/**
|
|
2515
|
+
* Plugin requirements (optional).
|
|
2516
|
+
*
|
|
2517
|
+
* Signal certain plugin requirements to the base class and the user.
|
|
2518
|
+
*
|
|
2519
|
+
* Currently supported:
|
|
2520
|
+
* - `launch`
|
|
2521
|
+
* - If the plugin only supports locally created browser instances (no `puppeteer.connect()`),
|
|
2522
|
+
* will output a warning to the user.
|
|
2523
|
+
* - `headful`
|
|
2524
|
+
* - If the plugin doesn't work in `headless: true` mode,
|
|
2525
|
+
* will output a warning to the user.
|
|
2526
|
+
* - `dataFromPlugins`
|
|
2527
|
+
* - In case the plugin requires data from other plugins.
|
|
2528
|
+
* will enable usage of `this.getDataFromPlugins()`.
|
|
2529
|
+
* - `runLast`
|
|
2530
|
+
* - In case the plugin prefers to run after the others.
|
|
2531
|
+
* Useful when the plugin needs data from others.
|
|
2532
|
+
*
|
|
2533
|
+
* @example
|
|
2534
|
+
* get requirements () {
|
|
2535
|
+
* return new Set(['runLast', 'dataFromPlugins'])
|
|
2536
|
+
* }
|
|
2537
|
+
*/
|
|
2538
|
+
get requirements() {
|
|
2539
|
+
return new Set([]);
|
|
2540
|
+
}
|
|
2541
|
+
/**
|
|
2542
|
+
* Plugin dependencies (optional).
|
|
2543
|
+
*
|
|
2544
|
+
* Missing plugins will be required() by puppeteer-extra.
|
|
2545
|
+
*
|
|
2546
|
+
* @example
|
|
2547
|
+
* get dependencies () {
|
|
2548
|
+
* return new Set(['user-preferences'])
|
|
2549
|
+
* }
|
|
2550
|
+
* // Will ensure the 'puppeteer-extra-plugin-user-preferences' plugin is loaded.
|
|
2551
|
+
*/
|
|
2552
|
+
get dependencies() {
|
|
2553
|
+
return new Set([]);
|
|
2554
|
+
}
|
|
2555
|
+
/**
|
|
2556
|
+
* Plugin data (optional).
|
|
2557
|
+
*
|
|
2558
|
+
* Plugins can expose data (an array of objects), which in turn can be consumed by other plugins,
|
|
2559
|
+
* that list the `dataFromPlugins` requirement (by using `this.getDataFromPlugins()`).
|
|
2560
|
+
*
|
|
2561
|
+
* Convention: `[ {name: 'Any name', value: 'Any value'} ]`
|
|
2562
|
+
*
|
|
2563
|
+
* @see [[getDataFromPlugins]]
|
|
2564
|
+
*
|
|
2565
|
+
* @example
|
|
2566
|
+
* // plugin1.js
|
|
2567
|
+
* get data () {
|
|
2568
|
+
* return [
|
|
2569
|
+
* {
|
|
2570
|
+
* name: 'userPreferences',
|
|
2571
|
+
* value: { foo: 'bar' }
|
|
2572
|
+
* },
|
|
2573
|
+
* {
|
|
2574
|
+
* name: 'userPreferences',
|
|
2575
|
+
* value: { hello: 'world' }
|
|
2576
|
+
* }
|
|
2577
|
+
* ]
|
|
2578
|
+
*
|
|
2579
|
+
* // plugin2.js
|
|
2580
|
+
* get requirements () { return new Set(['dataFromPlugins']) }
|
|
2581
|
+
*
|
|
2582
|
+
* async beforeLaunch () {
|
|
2583
|
+
* const prefs = this.getDataFromPlugins('userPreferences').map(d => d.value)
|
|
2584
|
+
* this.debug(prefs) // => [ { foo: 'bar' }, { hello: 'world' } ]
|
|
2585
|
+
* }
|
|
2586
|
+
*/
|
|
2587
|
+
get data() {
|
|
2588
|
+
return [];
|
|
2589
|
+
}
|
|
2590
|
+
/**
|
|
2591
|
+
* Access the plugin options (usually the `defaults` merged with user defined options)
|
|
2592
|
+
*
|
|
2593
|
+
* To skip the auto-merging of defaults with user supplied opts don't define a `defaults`
|
|
2594
|
+
* property and set the `this._opts` Object in your plugin constructor directly.
|
|
2595
|
+
*
|
|
2596
|
+
* @see [[defaults]]
|
|
2597
|
+
*
|
|
2598
|
+
* @example
|
|
2599
|
+
* get defaults () { return { foo: "bar" } }
|
|
2600
|
+
*
|
|
2601
|
+
* async onPageCreated (page) {
|
|
2602
|
+
* this.debug(this.opts.foo) // => bar
|
|
2603
|
+
* }
|
|
2604
|
+
*/
|
|
2605
|
+
get opts() {
|
|
2606
|
+
return this._opts;
|
|
2607
|
+
}
|
|
2608
|
+
/**
|
|
2609
|
+
* Convenience debug logger based on the [debug] module.
|
|
2610
|
+
* Will automatically namespace the logging output to the plugin package name.
|
|
2611
|
+
* [debug]: https://www.npmjs.com/package/debug
|
|
2612
|
+
*
|
|
2613
|
+
* ```bash
|
|
2614
|
+
* # toggle output using environment variables
|
|
2615
|
+
* DEBUG=puppeteer-extra-plugin:<plugin_name> node foo.js
|
|
2616
|
+
* # to debug all the things:
|
|
2617
|
+
* DEBUG=puppeteer-extra,puppeteer-extra-plugin:* node foo.js
|
|
2618
|
+
* ```
|
|
2619
|
+
*
|
|
2620
|
+
* @example
|
|
2621
|
+
* this.debug('hello world')
|
|
2622
|
+
* // will output e.g. 'puppeteer-extra-plugin:anonymize-ua hello world'
|
|
2623
|
+
*/
|
|
2624
|
+
get debug() {
|
|
2625
|
+
return debug$3(`puppeteer-extra-plugin:${this.name}`);
|
|
2626
|
+
}
|
|
2627
|
+
/**
|
|
2628
|
+
* Before a new browser instance is created/launched.
|
|
2629
|
+
*
|
|
2630
|
+
* Can be used to modify the puppeteer launch options by modifying or returning them.
|
|
2631
|
+
*
|
|
2632
|
+
* Plugins using this method will be called in sequence to each
|
|
2633
|
+
* be able to update the launch options.
|
|
2634
|
+
*
|
|
2635
|
+
* @example
|
|
2636
|
+
* async beforeLaunch (options) {
|
|
2637
|
+
* if (this.opts.flashPluginPath) {
|
|
2638
|
+
* options.args.push(`--ppapi-flash-path=${this.opts.flashPluginPath}`)
|
|
2639
|
+
* }
|
|
2640
|
+
* }
|
|
2641
|
+
*
|
|
2642
|
+
* @param options - Puppeteer launch options
|
|
2643
|
+
*/
|
|
2644
|
+
async beforeLaunch(options) {
|
|
2645
|
+
// noop
|
|
2646
|
+
}
|
|
2647
|
+
/**
|
|
2648
|
+
* After the browser has launched.
|
|
2649
|
+
*
|
|
2650
|
+
* Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
2651
|
+
* It's possible that `pupeeteer.launch` will be called multiple times and more than one browser created.
|
|
2652
|
+
* In order to make the plugins as stateless as possible don't store a reference to the browser instance
|
|
2653
|
+
* in the plugin but rather consider alternatives.
|
|
2654
|
+
*
|
|
2655
|
+
* E.g. when using `onPageCreated` you can get a browser reference by using `page.browser()`.
|
|
2656
|
+
*
|
|
2657
|
+
* Alternatively you could expose a class method that takes a browser instance as a parameter to work with:
|
|
2658
|
+
*
|
|
2659
|
+
* ```es6
|
|
2660
|
+
* const fancyPlugin = require('puppeteer-extra-plugin-fancy')()
|
|
2661
|
+
* puppeteer.use(fancyPlugin)
|
|
2662
|
+
* const browser = await puppeteer.launch()
|
|
2663
|
+
* await fancyPlugin.killBrowser(browser)
|
|
2664
|
+
* ```
|
|
2665
|
+
*
|
|
2666
|
+
* @param browser - The `puppeteer` browser instance.
|
|
2667
|
+
* @param opts.options - Puppeteer launch options used.
|
|
2668
|
+
*
|
|
2669
|
+
* @example
|
|
2670
|
+
* async afterLaunch (browser, opts) {
|
|
2671
|
+
* this.debug('browser has been launched', opts.options)
|
|
2672
|
+
* }
|
|
2673
|
+
*/
|
|
2674
|
+
async afterLaunch(browser, opts = { options: {} }) {
|
|
2675
|
+
// noop
|
|
2676
|
+
}
|
|
2677
|
+
/**
|
|
2678
|
+
* Before connecting to an existing browser instance.
|
|
2679
|
+
*
|
|
2680
|
+
* Can be used to modify the puppeteer connect options by modifying or returning them.
|
|
2681
|
+
*
|
|
2682
|
+
* Plugins using this method will be called in sequence to each
|
|
2683
|
+
* be able to update the launch options.
|
|
2684
|
+
*
|
|
2685
|
+
* @param {Object} options - Puppeteer connect options
|
|
2686
|
+
* @return {Object=}
|
|
2687
|
+
*/
|
|
2688
|
+
async beforeConnect(options) {
|
|
2689
|
+
// noop
|
|
2690
|
+
}
|
|
2691
|
+
/**
|
|
2692
|
+
* After connecting to an existing browser instance.
|
|
2693
|
+
*
|
|
2694
|
+
* > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
2695
|
+
*
|
|
2696
|
+
* @param browser - The `puppeteer` browser instance.
|
|
2697
|
+
* @param {Object} opts
|
|
2698
|
+
* @param {Object} opts.options - Puppeteer connect options used.
|
|
2699
|
+
*
|
|
2700
|
+
*/
|
|
2701
|
+
async afterConnect(browser, opts = {}) {
|
|
2702
|
+
// noop
|
|
2703
|
+
}
|
|
2704
|
+
/**
|
|
2705
|
+
* Called when a browser instance is available.
|
|
2706
|
+
*
|
|
2707
|
+
* This applies to both `puppeteer.launch()` and `puppeteer.connect()`.
|
|
2708
|
+
*
|
|
2709
|
+
* Convenience method created for plugins that need access to a browser instance
|
|
2710
|
+
* and don't mind if it has been created through `launch` or `connect`.
|
|
2711
|
+
*
|
|
2712
|
+
* > Note: Don't assume that there will only be a single browser instance during the lifecycle of a plugin.
|
|
2713
|
+
*
|
|
2714
|
+
* @param browser - The `puppeteer` browser instance.
|
|
2715
|
+
*/
|
|
2716
|
+
async onBrowser(browser, opts) {
|
|
2717
|
+
// noop
|
|
2718
|
+
}
|
|
2719
|
+
/**
|
|
2720
|
+
* Called when a target is created, for example when a new page is opened by window.open or browser.newPage.
|
|
2721
|
+
*
|
|
2722
|
+
* > Note: This includes target creations in incognito browser contexts.
|
|
2723
|
+
*
|
|
2724
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2725
|
+
*
|
|
2726
|
+
* @param {Puppeteer.Target} target
|
|
2727
|
+
*/
|
|
2728
|
+
async onTargetCreated(target) {
|
|
2729
|
+
// noop
|
|
2730
|
+
}
|
|
2731
|
+
/**
|
|
2732
|
+
* Same as `onTargetCreated` but prefiltered to only contain Pages, for convenience.
|
|
2733
|
+
*
|
|
2734
|
+
* > Note: This includes page creations in incognito browser contexts.
|
|
2735
|
+
*
|
|
2736
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2737
|
+
*
|
|
2738
|
+
* @param {Puppeteer.Target} target
|
|
2739
|
+
*
|
|
2740
|
+
* @example
|
|
2741
|
+
* async onPageCreated (page) {
|
|
2742
|
+
* let ua = await page.browser().userAgent()
|
|
2743
|
+
* if (this.opts.stripHeadless) {
|
|
2744
|
+
* ua = ua.replace('HeadlessChrome/', 'Chrome/')
|
|
2745
|
+
* }
|
|
2746
|
+
* this.debug('new ua', ua)
|
|
2747
|
+
* await page.setUserAgent(ua)
|
|
2748
|
+
* }
|
|
2749
|
+
*/
|
|
2750
|
+
async onPageCreated(page) {
|
|
2751
|
+
// noop
|
|
2752
|
+
}
|
|
2753
|
+
/**
|
|
2754
|
+
* Called when the url of a target changes.
|
|
2755
|
+
*
|
|
2756
|
+
* > Note: This includes target changes in incognito browser contexts.
|
|
2757
|
+
*
|
|
2758
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2759
|
+
*
|
|
2760
|
+
* @param {Puppeteer.Target} target
|
|
2761
|
+
*/
|
|
2762
|
+
async onTargetChanged(target) {
|
|
2763
|
+
// noop
|
|
2764
|
+
}
|
|
2765
|
+
/**
|
|
2766
|
+
* Called when a target is destroyed, for example when a page is closed.
|
|
2767
|
+
*
|
|
2768
|
+
* > Note: This includes target destructions in incognito browser contexts.
|
|
2769
|
+
*
|
|
2770
|
+
* > Note: This includes browser instances created through `.launch()` as well as `.connect()`.
|
|
2771
|
+
*
|
|
2772
|
+
* @param {Puppeteer.Target} target
|
|
2773
|
+
*/
|
|
2774
|
+
async onTargetDestroyed(target) {
|
|
2775
|
+
// noop
|
|
2776
|
+
}
|
|
2777
|
+
/**
|
|
2778
|
+
* Called when Puppeteer gets disconnected from the Chromium instance.
|
|
2779
|
+
*
|
|
2780
|
+
* This might happen because of one of the following:
|
|
2781
|
+
* - Chromium is closed or crashed
|
|
2782
|
+
* - The `browser.disconnect` method was called
|
|
2783
|
+
*/
|
|
2784
|
+
async onDisconnected() {
|
|
2785
|
+
// noop
|
|
2786
|
+
}
|
|
2787
|
+
/**
|
|
2788
|
+
* **Deprecated:** Since puppeteer v1.6.0 `onDisconnected` has been improved
|
|
2789
|
+
* and should be used instead of `onClose`.
|
|
2790
|
+
*
|
|
2791
|
+
* In puppeteer < v1.6.0 `onDisconnected` was not catching all exit scenarios.
|
|
2792
|
+
* In order for plugins to clean up properly (e.g. deleting temporary files)
|
|
2793
|
+
* the `onClose` method had been introduced.
|
|
2794
|
+
*
|
|
2795
|
+
* > Note: Might be called multiple times on exit.
|
|
2796
|
+
*
|
|
2797
|
+
* > Note: This only includes browser instances created through `.launch()`.
|
|
2798
|
+
*/
|
|
2799
|
+
async onClose() {
|
|
2800
|
+
// noop
|
|
2801
|
+
}
|
|
2802
|
+
/**
|
|
2803
|
+
* After the plugin has been registered in `puppeteer-extra`.
|
|
2804
|
+
*
|
|
2805
|
+
* Normally right after `puppeteer.use(plugin)` is called
|
|
2806
|
+
*/
|
|
2807
|
+
async onPluginRegistered() {
|
|
2808
|
+
// noop
|
|
2809
|
+
}
|
|
2810
|
+
/**
|
|
2811
|
+
* Helper method to retrieve `data` objects from other plugins.
|
|
2812
|
+
*
|
|
2813
|
+
* A plugin needs to state the `dataFromPlugins` requirement
|
|
2814
|
+
* in order to use this method. Will be mapped to `puppeteer.getPluginData`.
|
|
2815
|
+
*
|
|
2816
|
+
* @param name - Filter data by `name` property
|
|
2817
|
+
*
|
|
2818
|
+
* @see [data]
|
|
2819
|
+
* @see [requirements]
|
|
2820
|
+
*/
|
|
2821
|
+
getDataFromPlugins(name) {
|
|
2822
|
+
return [];
|
|
2823
|
+
}
|
|
2824
|
+
/**
|
|
2825
|
+
* Will match plugin dependencies against all currently registered plugins.
|
|
2826
|
+
* Is being called by `puppeteer-extra` and used to require missing dependencies.
|
|
2827
|
+
*
|
|
2828
|
+
* @param {Array<Object>} plugins
|
|
2829
|
+
* @return {Set} - list of missing plugin names
|
|
2830
|
+
*
|
|
2831
|
+
* @private
|
|
2832
|
+
*/
|
|
2833
|
+
_getMissingDependencies(plugins) {
|
|
2834
|
+
const pluginNames = new Set(plugins.map((p) => p.name));
|
|
2835
|
+
const missing = new Set(Array.from(this.dependencies.values()).filter(x => !pluginNames.has(x)));
|
|
2836
|
+
return missing;
|
|
2837
|
+
}
|
|
2838
|
+
/**
|
|
2839
|
+
* Conditionally bind browser/process events to class members.
|
|
2840
|
+
* The idea is to reduce event binding boilerplate in plugins.
|
|
2841
|
+
*
|
|
2842
|
+
* For efficiency we make sure the plugin is using the respective event
|
|
2843
|
+
* by checking the child class members before registering the listener.
|
|
2844
|
+
*
|
|
2845
|
+
* @param {<Puppeteer.Browser>} browser
|
|
2846
|
+
* @param {Object} opts - Options
|
|
2847
|
+
* @param {string} opts.context - Puppeteer context (launch/connect)
|
|
2848
|
+
* @param {Object} [opts.options] - Puppeteer launch or connect options
|
|
2849
|
+
* @param {Array<string>} [opts.defaultArgs] - The default flags that Chromium will be launched with
|
|
2850
|
+
*
|
|
2851
|
+
* @private
|
|
2852
|
+
*/
|
|
2853
|
+
async _bindBrowserEvents(browser, opts = {}) {
|
|
2854
|
+
if (this._hasChildClassMember('onTargetCreated') ||
|
|
2855
|
+
this._hasChildClassMember('onPageCreated')) {
|
|
2856
|
+
browser.on('targetcreated', this._onTargetCreated.bind(this));
|
|
2857
|
+
}
|
|
2858
|
+
if (this._hasChildClassMember('onTargetChanged') && this.onTargetChanged) {
|
|
2859
|
+
browser.on('targetchanged', this.onTargetChanged.bind(this));
|
|
2860
|
+
}
|
|
2861
|
+
if (this._hasChildClassMember('onTargetDestroyed') &&
|
|
2862
|
+
this.onTargetDestroyed) {
|
|
2863
|
+
browser.on('targetdestroyed', this.onTargetDestroyed.bind(this));
|
|
2864
|
+
}
|
|
2865
|
+
if (this._hasChildClassMember('onDisconnected') && this.onDisconnected) {
|
|
2866
|
+
browser.on('disconnected', this.onDisconnected.bind(this));
|
|
2867
|
+
}
|
|
2868
|
+
if (opts.context === 'launch' && this._hasChildClassMember('onClose')) {
|
|
2869
|
+
// The disconnect event has been improved since puppeteer v1.6.0
|
|
2870
|
+
// onClose is being kept mostly for legacy reasons
|
|
2871
|
+
if (this.onClose) {
|
|
2872
|
+
process.on('exit', this.onClose.bind(this));
|
|
2873
|
+
browser.on('disconnected', this.onClose.bind(this));
|
|
2874
|
+
if (opts.options.handleSIGINT !== false) {
|
|
2875
|
+
process.on('SIGINT', this.onClose.bind(this));
|
|
2876
|
+
}
|
|
2877
|
+
if (opts.options.handleSIGTERM !== false) {
|
|
2878
|
+
process.on('SIGTERM', this.onClose.bind(this));
|
|
2879
|
+
}
|
|
2880
|
+
if (opts.options.handleSIGHUP !== false) {
|
|
2881
|
+
process.on('SIGHUP', this.onClose.bind(this));
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
if (opts.context === 'launch' && this.afterLaunch) {
|
|
2886
|
+
await this.afterLaunch(browser, opts);
|
|
2887
|
+
}
|
|
2888
|
+
if (opts.context === 'connect' && this.afterConnect) {
|
|
2889
|
+
await this.afterConnect(browser, opts);
|
|
2890
|
+
}
|
|
2891
|
+
if (this.onBrowser)
|
|
2892
|
+
await this.onBrowser(browser, opts);
|
|
2893
|
+
}
|
|
2894
|
+
/**
|
|
2895
|
+
* @private
|
|
2896
|
+
*/
|
|
2897
|
+
async _onTargetCreated(target) {
|
|
2898
|
+
if (this.onTargetCreated)
|
|
2899
|
+
await this.onTargetCreated(target);
|
|
2900
|
+
// Pre filter pages for plugin developers convenience
|
|
2901
|
+
if (target.type() === 'page') {
|
|
2902
|
+
try {
|
|
2903
|
+
const page = await target.page();
|
|
2904
|
+
if (!page) {
|
|
2905
|
+
return;
|
|
2906
|
+
}
|
|
2907
|
+
const validPage = 'isClosed' in page && !page.isClosed();
|
|
2908
|
+
if (this.onPageCreated && validPage) {
|
|
2909
|
+
await this.onPageCreated(page);
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
catch (err) {
|
|
2913
|
+
console.error(err);
|
|
2914
|
+
}
|
|
2915
|
+
}
|
|
2916
|
+
}
|
|
2917
|
+
/**
|
|
2918
|
+
* @private
|
|
2919
|
+
*/
|
|
2920
|
+
_register(prototype) {
|
|
2921
|
+
this._registerChildClassMembers(prototype);
|
|
2922
|
+
if (this.onPluginRegistered)
|
|
2923
|
+
this.onPluginRegistered();
|
|
2924
|
+
}
|
|
2925
|
+
/**
|
|
2926
|
+
* @private
|
|
2927
|
+
*/
|
|
2928
|
+
_registerChildClassMembers(prototype) {
|
|
2929
|
+
this._childClassMembers = Object.getOwnPropertyNames(prototype);
|
|
2930
|
+
}
|
|
2931
|
+
/**
|
|
2932
|
+
* @private
|
|
2933
|
+
*/
|
|
2934
|
+
_hasChildClassMember(name) {
|
|
2935
|
+
return !!this._childClassMembers.includes(name);
|
|
2936
|
+
}
|
|
2937
|
+
/**
|
|
2938
|
+
* @private
|
|
2939
|
+
*/
|
|
2940
|
+
get _isPuppeteerExtraPlugin() {
|
|
2941
|
+
return true;
|
|
2942
|
+
}
|
|
2943
|
+
}
|
|
2944
|
+
|
|
2945
|
+
var index_esm = /*#__PURE__*/Object.freeze({
|
|
2946
|
+
__proto__: null,
|
|
2947
|
+
PuppeteerExtraPlugin: PuppeteerExtraPlugin$1
|
|
2948
|
+
});
|
|
2949
|
+
|
|
2950
|
+
var require$$0 = /*@__PURE__*/getAugmentedNamespace(index_esm);
|
|
2951
|
+
|
|
2952
|
+
const { PuppeteerExtraPlugin } = require$$0;
|
|
2953
|
+
|
|
2954
|
+
/**
|
|
2955
|
+
* Stealth mode: Applies various techniques to make detection of headless puppeteer harder. 💯
|
|
2956
|
+
*
|
|
2957
|
+
* ### Purpose
|
|
2958
|
+
* There are a couple of ways the use of puppeteer can easily be detected by a target website.
|
|
2959
|
+
* The addition of `HeadlessChrome` to the user-agent being only the most obvious one.
|
|
2960
|
+
*
|
|
2961
|
+
* The goal of this plugin is to be the definite companion to puppeteer to avoid
|
|
2962
|
+
* detection, applying new techniques as they surface.
|
|
2963
|
+
*
|
|
2964
|
+
* As this cat & mouse game is in it's infancy and fast-paced the plugin
|
|
2965
|
+
* is kept as flexibile as possible, to support quick testing and iterations.
|
|
2966
|
+
*
|
|
2967
|
+
* ### Modularity
|
|
2968
|
+
* This plugin uses `puppeteer-extra`'s dependency system to only require
|
|
2969
|
+
* code mods for evasions that have been enabled, to keep things modular and efficient.
|
|
2970
|
+
*
|
|
2971
|
+
* The `stealth` plugin is a convenience wrapper that requires multiple [evasion techniques](./evasions/)
|
|
2972
|
+
* automatically and comes with defaults. You could also bypass the main module and require
|
|
2973
|
+
* specific evasion plugins yourself, if you whish to do so (as they're standalone `puppeteer-extra` plugins):
|
|
2974
|
+
*
|
|
2975
|
+
* ```es6
|
|
2976
|
+
* // bypass main module and require a specific stealth plugin directly:
|
|
2977
|
+
* puppeteer.use(require('puppeteer-extra-plugin-stealth/evasions/console.debug')())
|
|
2978
|
+
* ```
|
|
2979
|
+
*
|
|
2980
|
+
* ### Contributing
|
|
2981
|
+
* PRs are welcome, if you want to add a new evasion technique I suggest you
|
|
2982
|
+
* look at the [template](./evasions/_template) to kickstart things.
|
|
2983
|
+
*
|
|
2984
|
+
* ### Kudos
|
|
2985
|
+
* Thanks to [Evan Sangaline](https://intoli.com/blog/not-possible-to-block-chrome-headless/) and [Paul Irish](https://github.com/paulirish/headless-cat-n-mouse) for kickstarting the discussion!
|
|
2986
|
+
*
|
|
2987
|
+
* ---
|
|
2988
|
+
*
|
|
2989
|
+
* @todo
|
|
2990
|
+
* - white-/blacklist with url globs (make this a generic plugin method?)
|
|
2991
|
+
* - dynamic whitelist based on function evaluation
|
|
2992
|
+
*
|
|
2993
|
+
* @example
|
|
2994
|
+
* const puppeteer = require('puppeteer-extra')
|
|
2995
|
+
* // Enable stealth plugin with all evasions
|
|
2996
|
+
* puppeteer.use(require('puppeteer-extra-plugin-stealth')())
|
|
2997
|
+
*
|
|
2998
|
+
*
|
|
2999
|
+
* ;(async () => {
|
|
3000
|
+
* // Launch the browser in headless mode and set up a page.
|
|
3001
|
+
* const browser = await puppeteer.launch({ args: ['--no-sandbox'], headless: true })
|
|
3002
|
+
* const page = await browser.newPage()
|
|
3003
|
+
*
|
|
3004
|
+
* // Navigate to the page that will perform the tests.
|
|
3005
|
+
* const testUrl = 'https://intoli.com/blog/' +
|
|
3006
|
+
* 'not-possible-to-block-chrome-headless/chrome-headless-test.html'
|
|
3007
|
+
* await page.goto(testUrl)
|
|
3008
|
+
*
|
|
3009
|
+
* // Save a screenshot of the results.
|
|
3010
|
+
* const screenshotPath = '/tmp/headless-test-result.png'
|
|
3011
|
+
* await page.screenshot({path: screenshotPath})
|
|
3012
|
+
* console.log('have a look at the screenshot:', screenshotPath)
|
|
3013
|
+
*
|
|
3014
|
+
* await browser.close()
|
|
3015
|
+
* })()
|
|
3016
|
+
*
|
|
3017
|
+
* @param {Object} [opts] - Options
|
|
3018
|
+
* @param {Set<string>} [opts.enabledEvasions] - Specify which evasions to use (by default all)
|
|
3019
|
+
*
|
|
3020
|
+
*/
|
|
3021
|
+
class StealthPlugin extends PuppeteerExtraPlugin {
|
|
3022
|
+
constructor(opts = {}) {
|
|
3023
|
+
super(opts);
|
|
3024
|
+
}
|
|
3025
|
+
|
|
3026
|
+
get name() {
|
|
3027
|
+
return 'stealth'
|
|
3028
|
+
}
|
|
3029
|
+
|
|
3030
|
+
get defaults() {
|
|
3031
|
+
const availableEvasions = new Set([
|
|
3032
|
+
'chrome.app',
|
|
3033
|
+
'chrome.csi',
|
|
3034
|
+
'chrome.loadTimes',
|
|
3035
|
+
'chrome.runtime',
|
|
3036
|
+
'defaultArgs',
|
|
3037
|
+
'iframe.contentWindow',
|
|
3038
|
+
'media.codecs',
|
|
3039
|
+
'navigator.hardwareConcurrency',
|
|
3040
|
+
'navigator.languages',
|
|
3041
|
+
'navigator.permissions',
|
|
3042
|
+
'navigator.plugins',
|
|
3043
|
+
'navigator.webdriver',
|
|
3044
|
+
'sourceurl',
|
|
3045
|
+
'user-agent-override',
|
|
3046
|
+
'webgl.vendor',
|
|
3047
|
+
'window.outerdimensions'
|
|
3048
|
+
]);
|
|
3049
|
+
return {
|
|
3050
|
+
availableEvasions,
|
|
3051
|
+
// Enable all available evasions by default
|
|
3052
|
+
enabledEvasions: new Set([...availableEvasions])
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
|
|
3056
|
+
/**
|
|
3057
|
+
* Requires evasion techniques dynamically based on configuration.
|
|
3058
|
+
*
|
|
3059
|
+
* @private
|
|
3060
|
+
*/
|
|
3061
|
+
get dependencies() {
|
|
3062
|
+
return new Set(
|
|
3063
|
+
[...this.opts.enabledEvasions].map(e => `${this.name}/evasions/${e}`)
|
|
3064
|
+
)
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
/**
|
|
3068
|
+
* Get all available evasions.
|
|
3069
|
+
*
|
|
3070
|
+
* Please look into the [evasions directory](./evasions/) for an up to date list.
|
|
3071
|
+
*
|
|
3072
|
+
* @type {Set<string>} - A Set of all available evasions.
|
|
3073
|
+
*
|
|
3074
|
+
* @example
|
|
3075
|
+
* const pluginStealth = require('puppeteer-extra-plugin-stealth')()
|
|
3076
|
+
* console.log(pluginStealth.availableEvasions) // => Set { 'user-agent', 'console.debug' }
|
|
3077
|
+
* puppeteer.use(pluginStealth)
|
|
3078
|
+
*/
|
|
3079
|
+
get availableEvasions() {
|
|
3080
|
+
return this.defaults.availableEvasions
|
|
3081
|
+
}
|
|
3082
|
+
|
|
3083
|
+
/**
|
|
3084
|
+
* Get all enabled evasions.
|
|
3085
|
+
*
|
|
3086
|
+
* Enabled evasions can be configured either through `opts` or by modifying this property.
|
|
3087
|
+
*
|
|
3088
|
+
* @type {Set<string>} - A Set of all enabled evasions.
|
|
3089
|
+
*
|
|
3090
|
+
* @example
|
|
3091
|
+
* // Remove specific evasion from enabled ones dynamically
|
|
3092
|
+
* const pluginStealth = require('puppeteer-extra-plugin-stealth')()
|
|
3093
|
+
* pluginStealth.enabledEvasions.delete('console.debug')
|
|
3094
|
+
* puppeteer.use(pluginStealth)
|
|
3095
|
+
*/
|
|
3096
|
+
get enabledEvasions() {
|
|
3097
|
+
return this.opts.enabledEvasions
|
|
3098
|
+
}
|
|
3099
|
+
|
|
3100
|
+
/**
|
|
3101
|
+
* @private
|
|
3102
|
+
*/
|
|
3103
|
+
set enabledEvasions(evasions) {
|
|
3104
|
+
this.opts.enabledEvasions = evasions;
|
|
3105
|
+
}
|
|
3106
|
+
|
|
3107
|
+
async onBrowser(browser) {
|
|
3108
|
+
if (browser && browser.setMaxListeners) {
|
|
3109
|
+
// Increase event emitter listeners to prevent MaxListenersExceededWarning
|
|
3110
|
+
browser.setMaxListeners(30);
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
|
|
3115
|
+
/**
|
|
3116
|
+
* Default export, PuppeteerExtraStealthPlugin
|
|
3117
|
+
*
|
|
3118
|
+
* @param {Object} [opts] - Options
|
|
3119
|
+
* @param {Set<string>} [opts.enabledEvasions] - Specify which evasions to use (by default all)
|
|
3120
|
+
*/
|
|
3121
|
+
const defaultExport = opts => new StealthPlugin(opts);
|
|
3122
|
+
var puppeteerExtraPluginStealth = defaultExport;
|
|
3123
|
+
|
|
3124
|
+
var stealth = test$1.extend({
|
|
3125
|
+
browser: async ({ browser }, use) => {
|
|
3126
|
+
await browser.close();
|
|
3127
|
+
chromium.use(puppeteerExtraPluginStealth());
|
|
3128
|
+
const stealthBrowser = await chromium.launch();
|
|
3129
|
+
await use(stealthBrowser);
|
|
3130
|
+
await stealthBrowser.close();
|
|
3131
|
+
},
|
|
3132
|
+
});
|
|
3133
|
+
|
|
318
3134
|
const LOWERCASED = "__LOWERCASED__";
|
|
319
3135
|
const FORMATS = {
|
|
320
3136
|
boldList: "boldList",
|
|
@@ -371,8 +3187,6 @@ const removeTagsProcessor = {
|
|
|
371
3187
|
},
|
|
372
3188
|
};
|
|
373
3189
|
|
|
374
|
-
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
375
|
-
|
|
376
3190
|
var tasks = {};
|
|
377
3191
|
|
|
378
3192
|
var utils$k = {};
|
|
@@ -435,8 +3249,8 @@ var path$a = {};
|
|
|
435
3249
|
|
|
436
3250
|
Object.defineProperty(path$a, "__esModule", { value: true });
|
|
437
3251
|
path$a.convertPosixPathToPattern = path$a.convertWindowsPathToPattern = path$a.convertPathToPattern = path$a.escapePosixPath = path$a.escapeWindowsPath = path$a.escape = path$a.removeLeadingDotSegment = path$a.makeAbsolute = path$a.unixify = void 0;
|
|
438
|
-
const os$1 = require$$2;
|
|
439
|
-
const path$9 = require$$0$
|
|
3252
|
+
const os$1 = require$$0$2;
|
|
3253
|
+
const path$9 = require$$0$4;
|
|
440
3254
|
const IS_WINDOWS_PLATFORM = os$1.platform() === 'win32';
|
|
441
3255
|
const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
|
|
442
3256
|
/**
|
|
@@ -676,8 +3490,8 @@ var isGlob$1 = function isGlob(str, options) {
|
|
|
676
3490
|
};
|
|
677
3491
|
|
|
678
3492
|
var isGlob = isGlob$1;
|
|
679
|
-
var pathPosixDirname = require$$0$
|
|
680
|
-
var isWin32 = require$$2.platform() === 'win32';
|
|
3493
|
+
var pathPosixDirname = require$$0$4.posix.dirname;
|
|
3494
|
+
var isWin32 = require$$0$2.platform() === 'win32';
|
|
681
3495
|
|
|
682
3496
|
var slash = '/';
|
|
683
3497
|
var backslash = /\\/g;
|
|
@@ -1173,7 +3987,7 @@ var toRegexRange_1 = toRegexRange$1;
|
|
|
1173
3987
|
* Licensed under the MIT License.
|
|
1174
3988
|
*/
|
|
1175
3989
|
|
|
1176
|
-
const util$1 = require$$0$
|
|
3990
|
+
const util$1 = require$$0$3;
|
|
1177
3991
|
const toRegexRange = toRegexRange_1;
|
|
1178
3992
|
|
|
1179
3993
|
const isObject$1 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
|
|
@@ -2140,7 +4954,7 @@ var picomatch$2 = {exports: {}};
|
|
|
2140
4954
|
|
|
2141
4955
|
var utils$f = {};
|
|
2142
4956
|
|
|
2143
|
-
const path$8 = require$$0$
|
|
4957
|
+
const path$8 = require$$0$4;
|
|
2144
4958
|
const WIN_SLASH = '\\\\/';
|
|
2145
4959
|
const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
|
|
2146
4960
|
|
|
@@ -2320,7 +5134,7 @@ var constants$3 = {
|
|
|
2320
5134
|
|
|
2321
5135
|
(function (exports) {
|
|
2322
5136
|
|
|
2323
|
-
const path = require$$0$
|
|
5137
|
+
const path = require$$0$4;
|
|
2324
5138
|
const win32 = process.platform === 'win32';
|
|
2325
5139
|
const {
|
|
2326
5140
|
REGEX_BACKSLASH,
|
|
@@ -3864,7 +6678,7 @@ parse$2.fastpaths = (input, options) => {
|
|
|
3864
6678
|
|
|
3865
6679
|
var parse_1 = parse$2;
|
|
3866
6680
|
|
|
3867
|
-
const path$7 = require$$0$
|
|
6681
|
+
const path$7 = require$$0$4;
|
|
3868
6682
|
const scan = scan_1;
|
|
3869
6683
|
const parse$1 = parse_1;
|
|
3870
6684
|
const utils$c = utils$f;
|
|
@@ -4210,7 +7024,7 @@ var picomatch_1 = picomatch$1;
|
|
|
4210
7024
|
module.exports = picomatch_1;
|
|
4211
7025
|
} (picomatch$2));
|
|
4212
7026
|
|
|
4213
|
-
const util = require$$0$
|
|
7027
|
+
const util = require$$0$3;
|
|
4214
7028
|
const braces = braces_1;
|
|
4215
7029
|
const picomatch = picomatch$2.exports;
|
|
4216
7030
|
const utils$b = utils$f;
|
|
@@ -4678,7 +7492,7 @@ var micromatch_1 = micromatch$1;
|
|
|
4678
7492
|
|
|
4679
7493
|
Object.defineProperty(pattern$1, "__esModule", { value: true });
|
|
4680
7494
|
pattern$1.removeDuplicateSlashes = pattern$1.matchAny = pattern$1.convertPatternsToRe = pattern$1.makeRe = pattern$1.getPatternParts = pattern$1.expandBraceExpansion = pattern$1.expandPatternsWithBraceExpansion = pattern$1.isAffectDepthOfReadingPattern = pattern$1.endsWithSlashGlobStar = pattern$1.hasGlobStar = pattern$1.getBaseDirectory = pattern$1.isPatternRelatedToParentDirectory = pattern$1.getPatternsOutsideCurrentDirectory = pattern$1.getPatternsInsideCurrentDirectory = pattern$1.getPositivePatterns = pattern$1.getNegativePatterns = pattern$1.isPositivePattern = pattern$1.isNegativePattern = pattern$1.convertToNegativePattern = pattern$1.convertToPositivePattern = pattern$1.isDynamicPattern = pattern$1.isStaticPattern = void 0;
|
|
4681
|
-
const path$6 = require$$0$
|
|
7495
|
+
const path$6 = require$$0$4;
|
|
4682
7496
|
const globParent = globParent$1;
|
|
4683
7497
|
const micromatch = micromatch_1;
|
|
4684
7498
|
const GLOBSTAR = '**';
|
|
@@ -4873,7 +7687,7 @@ var stream$4 = {};
|
|
|
4873
7687
|
* Copyright (c) 2014-2020 Teambition
|
|
4874
7688
|
* Licensed under the MIT license.
|
|
4875
7689
|
*/
|
|
4876
|
-
const Stream = require$$0$
|
|
7690
|
+
const Stream = require$$0$5;
|
|
4877
7691
|
const PassThrough = Stream.PassThrough;
|
|
4878
7692
|
const slice = Array.prototype.slice;
|
|
4879
7693
|
|
|
@@ -5623,7 +8437,7 @@ var fs$2 = {};
|
|
|
5623
8437
|
} (fs$2));
|
|
5624
8438
|
|
|
5625
8439
|
Object.defineProperty(settings$2, "__esModule", { value: true });
|
|
5626
|
-
const path$4 = require$$0$
|
|
8440
|
+
const path$4 = require$$0$4;
|
|
5627
8441
|
const fsStat$3 = out$1;
|
|
5628
8442
|
const fs$1 = fs$2;
|
|
5629
8443
|
class Settings$1 {
|
|
@@ -6042,7 +8856,7 @@ class Reader$1 {
|
|
|
6042
8856
|
reader$1.default = Reader$1;
|
|
6043
8857
|
|
|
6044
8858
|
Object.defineProperty(async$4, "__esModule", { value: true });
|
|
6045
|
-
const events_1 = require$$0$
|
|
8859
|
+
const events_1 = require$$0$6;
|
|
6046
8860
|
const fsScandir$2 = out$2;
|
|
6047
8861
|
const fastq = queue.exports;
|
|
6048
8862
|
const common$1 = common$3;
|
|
@@ -6171,7 +8985,7 @@ function callSuccessCallback(callback, entries) {
|
|
|
6171
8985
|
var stream$2 = {};
|
|
6172
8986
|
|
|
6173
8987
|
Object.defineProperty(stream$2, "__esModule", { value: true });
|
|
6174
|
-
const stream_1$5 = require$$0$
|
|
8988
|
+
const stream_1$5 = require$$0$5;
|
|
6175
8989
|
const async_1$3 = async$4;
|
|
6176
8990
|
class StreamProvider {
|
|
6177
8991
|
constructor(_root, _settings) {
|
|
@@ -6284,7 +9098,7 @@ sync$3.default = SyncProvider;
|
|
|
6284
9098
|
var settings$1 = {};
|
|
6285
9099
|
|
|
6286
9100
|
Object.defineProperty(settings$1, "__esModule", { value: true });
|
|
6287
|
-
const path$3 = require$$0$
|
|
9101
|
+
const path$3 = require$$0$4;
|
|
6288
9102
|
const fsScandir = out$2;
|
|
6289
9103
|
class Settings {
|
|
6290
9104
|
constructor(_options = {}) {
|
|
@@ -6346,7 +9160,7 @@ function getSettings(settingsOrOptions = {}) {
|
|
|
6346
9160
|
var reader = {};
|
|
6347
9161
|
|
|
6348
9162
|
Object.defineProperty(reader, "__esModule", { value: true });
|
|
6349
|
-
const path$2 = require$$0$
|
|
9163
|
+
const path$2 = require$$0$4;
|
|
6350
9164
|
const fsStat$2 = out$1;
|
|
6351
9165
|
const utils$6 = utils$k;
|
|
6352
9166
|
class Reader {
|
|
@@ -6381,7 +9195,7 @@ reader.default = Reader;
|
|
|
6381
9195
|
var stream$1 = {};
|
|
6382
9196
|
|
|
6383
9197
|
Object.defineProperty(stream$1, "__esModule", { value: true });
|
|
6384
|
-
const stream_1$3 = require$$0$
|
|
9198
|
+
const stream_1$3 = require$$0$5;
|
|
6385
9199
|
const fsStat$1 = out$1;
|
|
6386
9200
|
const fsWalk$2 = out$3;
|
|
6387
9201
|
const reader_1$2 = reader;
|
|
@@ -6734,7 +9548,7 @@ class EntryTransformer {
|
|
|
6734
9548
|
entry.default = EntryTransformer;
|
|
6735
9549
|
|
|
6736
9550
|
Object.defineProperty(provider, "__esModule", { value: true });
|
|
6737
|
-
const path$1 = require$$0$
|
|
9551
|
+
const path$1 = require$$0$4;
|
|
6738
9552
|
const deep_1 = deep;
|
|
6739
9553
|
const entry_1 = entry$1;
|
|
6740
9554
|
const error_1 = error;
|
|
@@ -6807,7 +9621,7 @@ async$7.default = ProviderAsync;
|
|
|
6807
9621
|
var stream = {};
|
|
6808
9622
|
|
|
6809
9623
|
Object.defineProperty(stream, "__esModule", { value: true });
|
|
6810
|
-
const stream_1$1 = require$$0$
|
|
9624
|
+
const stream_1$1 = require$$0$5;
|
|
6811
9625
|
const stream_2 = stream$1;
|
|
6812
9626
|
const provider_1$1 = provider;
|
|
6813
9627
|
class ProviderStream extends provider_1$1.default {
|
|
@@ -6913,7 +9727,7 @@ var settings = {};
|
|
|
6913
9727
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6914
9728
|
exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
|
|
6915
9729
|
const fs = require$$0__default;
|
|
6916
|
-
const os = require$$2;
|
|
9730
|
+
const os = require$$0$2;
|
|
6917
9731
|
/**
|
|
6918
9732
|
* The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
|
|
6919
9733
|
* https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107
|
|
@@ -8221,8 +11035,8 @@ var require$$4 = {
|
|
|
8221
11035
|
};
|
|
8222
11036
|
|
|
8223
11037
|
const fs = require$$0__default;
|
|
8224
|
-
const path = require$$0$
|
|
8225
|
-
const os = require$$2;
|
|
11038
|
+
const path = require$$0$4;
|
|
11039
|
+
const os = require$$0$2;
|
|
8226
11040
|
const crypto = require$$3;
|
|
8227
11041
|
const packageJson = require$$4;
|
|
8228
11042
|
|
|
@@ -8622,7 +11436,7 @@ const env = main$2.exports.config({
|
|
|
8622
11436
|
path: `./e2e/config/.env.${process.env.TEST_ENV}`,
|
|
8623
11437
|
});
|
|
8624
11438
|
main.expand(env);
|
|
8625
|
-
if (require$$0.existsSync("./e2e/config/.env.local")) {
|
|
11439
|
+
if (require$$0$1.existsSync("./e2e/config/.env.local")) {
|
|
8626
11440
|
const localEnv = main$2.exports.config({
|
|
8627
11441
|
path: "./e2e/config/.env.local",
|
|
8628
11442
|
});
|
|
@@ -8674,5 +11488,5 @@ const definePlaywrightConfig = (overrides) => {
|
|
|
8674
11488
|
});
|
|
8675
11489
|
};
|
|
8676
11490
|
|
|
8677
|
-
export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, CHAT_WIDGET_TEXTS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, INTEGRATIONS_TEXTS, INTEGRATION_SELECTORS, IS_STAGING_ENV, IntegrationBase, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MEMBER_TEXTS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, SLACK_DEFAULT_CHANNEL, SLACK_SELECTORS, SLACK_WEB_TEXTS, STORAGE_STATE, SlackPage, TAGS_SELECTORS, THIRD_PARTY_ROUTES, USER_AGENTS, WebhooksPage, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, tableUtils, updateCredentials, writeDataToFile };
|
|
11491
|
+
export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, CHAT_WIDGET_TEXTS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, INTEGRATIONS_TEXTS, INTEGRATION_SELECTORS, IS_STAGING_ENV, IntegrationBase, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MEMBER_TEXTS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, SLACK_DEFAULT_CHANNEL, SLACK_SELECTORS, SLACK_WEB_TEXTS, STORAGE_STATE, SlackPage, TAGS_SELECTORS, THIRD_PARTY_ROUTES, USER_AGENTS, WebhooksPage, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, stealth as stealthTest, tableUtils, updateCredentials, writeDataToFile };
|
|
8678
11492
|
//# sourceMappingURL=index.js.map
|