@bigbinary/neeto-playwright-commons 4.0.0 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +24 -916
- package/package.json +3 -4
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import fs__default, { readFileSync, promises, existsSync, writeFileSync, unlinkS
|
|
|
5
5
|
import os from 'os';
|
|
6
6
|
import * as path from 'path';
|
|
7
7
|
import path__default, { dirname } from 'path';
|
|
8
|
-
import test, { expect, test as test$1, chromium
|
|
8
|
+
import test, { expect, test as test$1, chromium, defineConfig, devices } from '@playwright/test';
|
|
9
9
|
import { getI18nInstance, initI18n } from 'playwright-i18next-fixture';
|
|
10
10
|
import { curry, isNotNil, not, isEmpty, pluck, mergeAll, isNil, mergeDeepLeft } from 'ramda';
|
|
11
11
|
import { execSync, spawn } from 'child_process';
|
|
@@ -25,6 +25,7 @@ import require$$1$5 from 'string_decoder';
|
|
|
25
25
|
import require$$0$b from 'node:buffer';
|
|
26
26
|
import require$$1$6 from 'node:stream';
|
|
27
27
|
import require$$1$7 from 'zlib';
|
|
28
|
+
import { addExtra } from 'playwright-extra';
|
|
28
29
|
import stealth$1 from 'puppeteer-extra-plugin-stealth';
|
|
29
30
|
import { globSync } from 'node:fs';
|
|
30
31
|
import customParseFormat from 'dayjs/plugin/customParseFormat.js';
|
|
@@ -4688,7 +4689,7 @@ var dbsize = {
|
|
|
4688
4689
|
keyStop: 0,
|
|
4689
4690
|
step: 0
|
|
4690
4691
|
};
|
|
4691
|
-
var debug$
|
|
4692
|
+
var debug$1 = {
|
|
4692
4693
|
arity: -2,
|
|
4693
4694
|
flags: [
|
|
4694
4695
|
"admin",
|
|
@@ -7014,7 +7015,7 @@ var require$$0$3 = {
|
|
|
7014
7015
|
config: config$1,
|
|
7015
7016
|
copy: copy,
|
|
7016
7017
|
dbsize: dbsize,
|
|
7017
|
-
debug: debug$
|
|
7018
|
+
debug: debug$1,
|
|
7018
7019
|
decr: decr,
|
|
7019
7020
|
decrby: decrby,
|
|
7020
7021
|
del: del,
|
|
@@ -8906,7 +8907,7 @@ function requireLodash () {
|
|
|
8906
8907
|
return lodash;
|
|
8907
8908
|
}
|
|
8908
8909
|
|
|
8909
|
-
var debug
|
|
8910
|
+
var debug = {};
|
|
8910
8911
|
|
|
8911
8912
|
var src$2 = {exports: {}};
|
|
8912
8913
|
|
|
@@ -10099,13 +10100,13 @@ function requireSrc$2 () {
|
|
|
10099
10100
|
var hasRequiredDebug;
|
|
10100
10101
|
|
|
10101
10102
|
function requireDebug () {
|
|
10102
|
-
if (hasRequiredDebug) return debug
|
|
10103
|
+
if (hasRequiredDebug) return debug;
|
|
10103
10104
|
hasRequiredDebug = 1;
|
|
10104
|
-
Object.defineProperty(debug
|
|
10105
|
-
debug
|
|
10105
|
+
Object.defineProperty(debug, "__esModule", { value: true });
|
|
10106
|
+
debug.genRedactedString = debug.getStringValue = debug.MAX_ARGUMENT_LENGTH = void 0;
|
|
10106
10107
|
const debug_1 = requireSrc$2();
|
|
10107
10108
|
const MAX_ARGUMENT_LENGTH = 200;
|
|
10108
|
-
debug
|
|
10109
|
+
debug.MAX_ARGUMENT_LENGTH = MAX_ARGUMENT_LENGTH;
|
|
10109
10110
|
const NAMESPACE_PREFIX = "ioredis";
|
|
10110
10111
|
/**
|
|
10111
10112
|
* helper function that tried to get a string value for
|
|
@@ -10137,7 +10138,7 @@ function requireDebug () {
|
|
|
10137
10138
|
return v;
|
|
10138
10139
|
}
|
|
10139
10140
|
}
|
|
10140
|
-
debug
|
|
10141
|
+
debug.getStringValue = getStringValue;
|
|
10141
10142
|
/**
|
|
10142
10143
|
* helper function that redacts a string representation of a "debug" arg
|
|
10143
10144
|
*/
|
|
@@ -10147,7 +10148,7 @@ function requireDebug () {
|
|
|
10147
10148
|
? str
|
|
10148
10149
|
: str.slice(0, maxLen) + ' ... <REDACTED full-length="' + length + '">';
|
|
10149
10150
|
}
|
|
10150
|
-
debug
|
|
10151
|
+
debug.genRedactedString = genRedactedString;
|
|
10151
10152
|
/**
|
|
10152
10153
|
* a wrapper for the `debug` module, used to generate
|
|
10153
10154
|
* "debug functions" that trim the values in their output
|
|
@@ -10194,8 +10195,8 @@ function requireDebug () {
|
|
|
10194
10195
|
});
|
|
10195
10196
|
return wrappedDebug;
|
|
10196
10197
|
}
|
|
10197
|
-
debug
|
|
10198
|
-
return debug
|
|
10198
|
+
debug.default = genDebugFunction;
|
|
10199
|
+
return debug;
|
|
10199
10200
|
}
|
|
10200
10201
|
|
|
10201
10202
|
var TLSProfiles = {};
|
|
@@ -77076,16 +77077,16 @@ function requireSrc () {
|
|
|
77076
77077
|
return src;
|
|
77077
77078
|
}
|
|
77078
77079
|
|
|
77079
|
-
var srcExports
|
|
77080
|
+
var srcExports = requireSrc();
|
|
77080
77081
|
|
|
77081
77082
|
function gif() {
|
|
77082
77083
|
return {
|
|
77083
77084
|
mime: "image/gif",
|
|
77084
77085
|
encode: async (bitmap) => {
|
|
77085
|
-
const gif = new srcExports
|
|
77086
|
-
srcExports
|
|
77087
|
-
const newFrame = new srcExports
|
|
77088
|
-
const gifCodec = new srcExports
|
|
77086
|
+
const gif = new srcExports.BitmapImage(bitmap);
|
|
77087
|
+
srcExports.GifUtil.quantizeDekker(gif, 256);
|
|
77088
|
+
const newFrame = new srcExports.GifFrame(bitmap);
|
|
77089
|
+
const gifCodec = new srcExports.GifCodec();
|
|
77089
77090
|
const newGif = await gifCodec.encodeGif([newFrame], {});
|
|
77090
77091
|
return newGif.buffer;
|
|
77091
77092
|
},
|
|
@@ -116572,904 +116573,11 @@ const commands = {
|
|
|
116572
116573
|
},
|
|
116573
116574
|
};
|
|
116574
116575
|
|
|
116575
|
-
var srcExports = requireSrc$2();
|
|
116576
|
-
var Debug = /*@__PURE__*/getDefaultExportFromCjs(srcExports);
|
|
116577
|
-
|
|
116578
|
-
/*!
|
|
116579
|
-
* playwright-extra v4.3.5 by berstend
|
|
116580
|
-
* https://github.com/berstend/puppeteer-extra/tree/master/packages/playwright-extra#readme
|
|
116581
|
-
* @license MIT
|
|
116582
|
-
*/
|
|
116583
|
-
|
|
116584
|
-
/** Node.js module loader helper */
|
|
116585
|
-
class Loader {
|
|
116586
|
-
constructor(moduleName, packageNames) {
|
|
116587
|
-
this.moduleName = moduleName;
|
|
116588
|
-
this.packageNames = packageNames;
|
|
116589
|
-
}
|
|
116590
|
-
/**
|
|
116591
|
-
* Lazy load a top level export from another module by wrapping it in a JS proxy.
|
|
116592
|
-
*
|
|
116593
|
-
* This allows us to re-export e.g. `devices` from `playwright` while redirecting direct calls
|
|
116594
|
-
* to it to the module version the user has installed, rather than shipping with a hardcoded version.
|
|
116595
|
-
*
|
|
116596
|
-
* 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.
|
|
116597
|
-
*
|
|
116598
|
-
* We use a "super" Proxy defining all traps, so calls like `Object.keys(playwright.devices).length` will return the correct value.
|
|
116599
|
-
*/
|
|
116600
|
-
lazyloadExportOrDie(exportName) {
|
|
116601
|
-
const that = this;
|
|
116602
|
-
const trapHandler = Object.fromEntries(Object.getOwnPropertyNames(Reflect).map((name) => [
|
|
116603
|
-
name,
|
|
116604
|
-
function (target, ...args) {
|
|
116605
|
-
const moduleExport = that.loadModuleOrDie()[exportName];
|
|
116606
|
-
const customTarget = moduleExport;
|
|
116607
|
-
const result = Reflect[name](customTarget || target, ...args);
|
|
116608
|
-
return result;
|
|
116609
|
-
}
|
|
116610
|
-
]));
|
|
116611
|
-
return new Proxy({}, trapHandler);
|
|
116612
|
-
}
|
|
116613
|
-
/** Load the module if possible */
|
|
116614
|
-
loadModule() {
|
|
116615
|
-
return requirePackages(this.packageNames);
|
|
116616
|
-
}
|
|
116617
|
-
/** Load the module if possible or throw */
|
|
116618
|
-
loadModuleOrDie() {
|
|
116619
|
-
const module = requirePackages(this.packageNames);
|
|
116620
|
-
if (module) {
|
|
116621
|
-
return module;
|
|
116622
|
-
}
|
|
116623
|
-
throw this.requireError;
|
|
116624
|
-
}
|
|
116625
|
-
get requireError() {
|
|
116626
|
-
const moduleNamePretty = this.moduleName.charAt(0).toUpperCase() + this.moduleName.slice(1);
|
|
116627
|
-
return new Error(`
|
|
116628
|
-
${moduleNamePretty} is missing. :-)
|
|
116629
|
-
|
|
116630
|
-
I've tried loading ${this.packageNames
|
|
116631
|
-
.map(p => `"${p}"`)
|
|
116632
|
-
.join(', ')} - no luck.
|
|
116633
|
-
|
|
116634
|
-
Make sure you install one of those packages or use the named 'addExtra' export,
|
|
116635
|
-
to patch a specific (and maybe non-standard) implementation of ${moduleNamePretty}.
|
|
116636
|
-
|
|
116637
|
-
To get the latest stable version of ${moduleNamePretty} run:
|
|
116638
|
-
'yarn add ${this.moduleName}' or 'npm i ${this.moduleName}'
|
|
116639
|
-
`);
|
|
116640
|
-
}
|
|
116641
|
-
}
|
|
116642
|
-
function requirePackages(packageNames) {
|
|
116643
|
-
for (const name of packageNames) {
|
|
116644
|
-
try {
|
|
116645
|
-
return require(name);
|
|
116646
|
-
}
|
|
116647
|
-
catch (_) {
|
|
116648
|
-
continue; // noop
|
|
116649
|
-
}
|
|
116650
|
-
}
|
|
116651
|
-
return;
|
|
116652
|
-
}
|
|
116653
|
-
/** Playwright specific module loader */
|
|
116654
|
-
const playwrightLoader = new Loader('playwright', [
|
|
116655
|
-
'playwright-core',
|
|
116656
|
-
'playwright'
|
|
116657
|
-
]);
|
|
116658
|
-
|
|
116659
|
-
const debug = Debug('playwright-extra:puppeteer-compat');
|
|
116660
|
-
const isPlaywrightPage = (obj) => {
|
|
116661
|
-
return 'unroute' in obj;
|
|
116662
|
-
};
|
|
116663
|
-
const isPlaywrightFrame = (obj) => {
|
|
116664
|
-
return ['parentFrame', 'frameLocator'].every(x => x in obj);
|
|
116665
|
-
};
|
|
116666
|
-
const isPlaywrightBrowser = (obj) => {
|
|
116667
|
-
return 'newContext' in obj;
|
|
116668
|
-
};
|
|
116669
|
-
const isPuppeteerCompat = (obj) => {
|
|
116670
|
-
return !!obj && typeof obj === 'object' && !!obj.isCompatShim;
|
|
116671
|
-
};
|
|
116672
|
-
const cache = {
|
|
116673
|
-
objectToShim: new Map(),
|
|
116674
|
-
cdpSession: {
|
|
116675
|
-
page: new Map(),
|
|
116676
|
-
browser: new Map()
|
|
116677
|
-
}
|
|
116678
|
-
};
|
|
116679
|
-
/** Augment a Playwright object with compatibility with certain Puppeteer methods */
|
|
116680
|
-
function addPuppeteerCompat(object) {
|
|
116681
|
-
if (!object || typeof object !== 'object') {
|
|
116682
|
-
return object;
|
|
116683
|
-
}
|
|
116684
|
-
if (cache.objectToShim.has(object)) {
|
|
116685
|
-
return cache.objectToShim.get(object);
|
|
116686
|
-
}
|
|
116687
|
-
if (isPuppeteerCompat(object)) {
|
|
116688
|
-
return object;
|
|
116689
|
-
}
|
|
116690
|
-
debug('addPuppeteerCompat', cache.objectToShim.size);
|
|
116691
|
-
if (isPlaywrightPage(object) || isPlaywrightFrame(object)) {
|
|
116692
|
-
const shim = createPageShim(object);
|
|
116693
|
-
cache.objectToShim.set(object, shim);
|
|
116694
|
-
return shim;
|
|
116695
|
-
}
|
|
116696
|
-
if (isPlaywrightBrowser(object)) {
|
|
116697
|
-
const shim = createBrowserShim(object);
|
|
116698
|
-
cache.objectToShim.set(object, shim);
|
|
116699
|
-
return shim;
|
|
116700
|
-
}
|
|
116701
|
-
debug('Received unknown object:', Reflect.ownKeys(object));
|
|
116702
|
-
return object;
|
|
116703
|
-
}
|
|
116704
|
-
// Only chromium browsers support CDP
|
|
116705
|
-
const dummyCDPClient = {
|
|
116706
|
-
send: async (...args) => {
|
|
116707
|
-
debug('dummy CDP client called', 'send', args);
|
|
116708
|
-
},
|
|
116709
|
-
on: (...args) => {
|
|
116710
|
-
debug('dummy CDP client called', 'on', args);
|
|
116711
|
-
}
|
|
116712
|
-
};
|
|
116713
|
-
async function getPageCDPSession(page) {
|
|
116714
|
-
let session = cache.cdpSession.page.get(page);
|
|
116715
|
-
if (session) {
|
|
116716
|
-
debug('getPageCDPSession: use existing');
|
|
116717
|
-
return session;
|
|
116718
|
-
}
|
|
116719
|
-
debug('getPageCDPSession: use new');
|
|
116720
|
-
const context = isPlaywrightFrame(page)
|
|
116721
|
-
? page.page().context()
|
|
116722
|
-
: page.context();
|
|
116723
|
-
try {
|
|
116724
|
-
session = await context.newCDPSession(page);
|
|
116725
|
-
cache.cdpSession.page.set(page, session);
|
|
116726
|
-
return session;
|
|
116727
|
-
}
|
|
116728
|
-
catch (err) {
|
|
116729
|
-
debug('getPageCDPSession: error while creating session:', err.message);
|
|
116730
|
-
debug('getPageCDPSession: Unable create CDP session (most likely a different browser than chromium) - returning a dummy');
|
|
116731
|
-
}
|
|
116732
|
-
return dummyCDPClient;
|
|
116733
|
-
}
|
|
116734
|
-
async function getBrowserCDPSession(browser) {
|
|
116735
|
-
let session = cache.cdpSession.browser.get(browser);
|
|
116736
|
-
if (session) {
|
|
116737
|
-
debug('getBrowserCDPSession: use existing');
|
|
116738
|
-
return session;
|
|
116739
|
-
}
|
|
116740
|
-
debug('getBrowserCDPSession: use new');
|
|
116741
|
-
try {
|
|
116742
|
-
session = await browser.newBrowserCDPSession();
|
|
116743
|
-
cache.cdpSession.browser.set(browser, session);
|
|
116744
|
-
return session;
|
|
116745
|
-
}
|
|
116746
|
-
catch (err) {
|
|
116747
|
-
debug('getBrowserCDPSession: error while creating session:', err.message);
|
|
116748
|
-
debug('getBrowserCDPSession: Unable create CDP session (most likely a different browser than chromium) - returning a dummy');
|
|
116749
|
-
}
|
|
116750
|
-
return dummyCDPClient;
|
|
116751
|
-
}
|
|
116752
|
-
function createPageShim(page) {
|
|
116753
|
-
const objId = Math.random().toString(36).substring(2, 7);
|
|
116754
|
-
const shim = new Proxy(page, {
|
|
116755
|
-
get(target, prop) {
|
|
116756
|
-
if (prop === 'isCompatShim' || prop === 'isPlaywright') {
|
|
116757
|
-
return true;
|
|
116758
|
-
}
|
|
116759
|
-
debug('page - get', objId, prop);
|
|
116760
|
-
if (prop === '_client') {
|
|
116761
|
-
return () => ({
|
|
116762
|
-
send: async (method, params) => {
|
|
116763
|
-
const session = await getPageCDPSession(page);
|
|
116764
|
-
return await session.send(method, params);
|
|
116765
|
-
},
|
|
116766
|
-
on: (event, listener) => {
|
|
116767
|
-
getPageCDPSession(page).then(session => {
|
|
116768
|
-
session.on(event, listener);
|
|
116769
|
-
});
|
|
116770
|
-
}
|
|
116771
|
-
});
|
|
116772
|
-
}
|
|
116773
|
-
if (prop === 'setBypassCSP') {
|
|
116774
|
-
return async (enabled) => {
|
|
116775
|
-
const session = await getPageCDPSession(page);
|
|
116776
|
-
return await session.send('Page.setBypassCSP', {
|
|
116777
|
-
enabled
|
|
116778
|
-
});
|
|
116779
|
-
};
|
|
116780
|
-
}
|
|
116781
|
-
if (prop === 'setUserAgent') {
|
|
116782
|
-
return async (userAgent, userAgentMetadata) => {
|
|
116783
|
-
const session = await getPageCDPSession(page);
|
|
116784
|
-
return await session.send('Emulation.setUserAgentOverride', {
|
|
116785
|
-
userAgent,
|
|
116786
|
-
userAgentMetadata
|
|
116787
|
-
});
|
|
116788
|
-
};
|
|
116789
|
-
}
|
|
116790
|
-
if (prop === 'browser') {
|
|
116791
|
-
if (isPlaywrightPage(page)) {
|
|
116792
|
-
return () => {
|
|
116793
|
-
let browser = page.context().browser();
|
|
116794
|
-
if (!browser) {
|
|
116795
|
-
debug('page.browser() - not available, most likely due to launchPersistentContext');
|
|
116796
|
-
// Use a page shim as quick drop-in (so browser.userAgent() still works)
|
|
116797
|
-
browser = page;
|
|
116798
|
-
}
|
|
116799
|
-
return addPuppeteerCompat(browser);
|
|
116800
|
-
};
|
|
116801
|
-
}
|
|
116802
|
-
}
|
|
116803
|
-
if (prop === 'evaluateOnNewDocument') {
|
|
116804
|
-
if (isPlaywrightPage(page)) {
|
|
116805
|
-
return async function (pageFunction, ...args) {
|
|
116806
|
-
return await page.addInitScript(pageFunction, args[0]);
|
|
116807
|
-
};
|
|
116808
|
-
}
|
|
116809
|
-
}
|
|
116810
|
-
// Only relevant when page is being used a pseudo stand-in for the browser object (launchPersistentContext)
|
|
116811
|
-
if (prop === 'userAgent') {
|
|
116812
|
-
return async (enabled) => {
|
|
116813
|
-
const session = await getPageCDPSession(page);
|
|
116814
|
-
const data = await session.send('Browser.getVersion');
|
|
116815
|
-
return data.userAgent;
|
|
116816
|
-
};
|
|
116817
|
-
}
|
|
116818
|
-
return Reflect.get(target, prop);
|
|
116819
|
-
}
|
|
116820
|
-
});
|
|
116821
|
-
return shim;
|
|
116822
|
-
}
|
|
116823
|
-
function createBrowserShim(browser) {
|
|
116824
|
-
const objId = Math.random().toString(36).substring(2, 7);
|
|
116825
|
-
const shim = new Proxy(browser, {
|
|
116826
|
-
get(target, prop) {
|
|
116827
|
-
if (prop === 'isCompatShim' || prop === 'isPlaywright') {
|
|
116828
|
-
return true;
|
|
116829
|
-
}
|
|
116830
|
-
debug('browser - get', objId, prop);
|
|
116831
|
-
if (prop === 'pages') {
|
|
116832
|
-
return () => browser
|
|
116833
|
-
.contexts()
|
|
116834
|
-
.flatMap(c => c.pages().map(page => addPuppeteerCompat(page)));
|
|
116835
|
-
}
|
|
116836
|
-
if (prop === 'userAgent') {
|
|
116837
|
-
return async () => {
|
|
116838
|
-
const session = await getBrowserCDPSession(browser);
|
|
116839
|
-
const data = await session.send('Browser.getVersion');
|
|
116840
|
-
return data.userAgent;
|
|
116841
|
-
};
|
|
116842
|
-
}
|
|
116843
|
-
return Reflect.get(target, prop);
|
|
116844
|
-
}
|
|
116845
|
-
});
|
|
116846
|
-
return shim;
|
|
116847
|
-
}
|
|
116848
|
-
|
|
116849
|
-
const debug$1 = Debug('playwright-extra:plugins');
|
|
116850
|
-
class PluginList {
|
|
116851
|
-
constructor() {
|
|
116852
|
-
this._plugins = [];
|
|
116853
|
-
this._dependencyDefaults = new Map();
|
|
116854
|
-
this._dependencyResolution = new Map();
|
|
116855
|
-
}
|
|
116856
|
-
/**
|
|
116857
|
-
* Get a list of all registered plugins.
|
|
116858
|
-
*/
|
|
116859
|
-
get list() {
|
|
116860
|
-
return this._plugins;
|
|
116861
|
-
}
|
|
116862
|
-
/**
|
|
116863
|
-
* Get the names of all registered plugins.
|
|
116864
|
-
*/
|
|
116865
|
-
get names() {
|
|
116866
|
-
return this._plugins.map(p => p.name);
|
|
116867
|
-
}
|
|
116868
|
-
/**
|
|
116869
|
-
* Add a new plugin to the list (after checking if it's well-formed).
|
|
116870
|
-
*
|
|
116871
|
-
* @param plugin
|
|
116872
|
-
* @internal
|
|
116873
|
-
*/
|
|
116874
|
-
add(plugin) {
|
|
116875
|
-
var _a;
|
|
116876
|
-
if (!this.isValidPluginInstance(plugin)) {
|
|
116877
|
-
return false;
|
|
116878
|
-
}
|
|
116879
|
-
if (!!plugin.onPluginRegistered) {
|
|
116880
|
-
plugin.onPluginRegistered({ framework: 'playwright' });
|
|
116881
|
-
}
|
|
116882
|
-
// PuppeteerExtraPlugin: Populate `_childClassMembers` list containing methods defined by the plugin
|
|
116883
|
-
if (!!plugin._registerChildClassMembers) {
|
|
116884
|
-
plugin._registerChildClassMembers(Object.getPrototypeOf(plugin));
|
|
116885
|
-
}
|
|
116886
|
-
if ((_a = plugin.requirements) === null || _a === void 0 ? void 0 : _a.has('dataFromPlugins')) {
|
|
116887
|
-
plugin.getDataFromPlugins = this.getData.bind(this);
|
|
116888
|
-
}
|
|
116889
|
-
this._plugins.push(plugin);
|
|
116890
|
-
return true;
|
|
116891
|
-
}
|
|
116892
|
-
/** Check if the shape of a plugin is correct or warn */
|
|
116893
|
-
isValidPluginInstance(plugin) {
|
|
116894
|
-
if (!plugin ||
|
|
116895
|
-
typeof plugin !== 'object' ||
|
|
116896
|
-
!plugin._isPuppeteerExtraPlugin) {
|
|
116897
|
-
console.error(`Warning: Plugin is not derived from PuppeteerExtraPlugin, ignoring.`, plugin);
|
|
116898
|
-
return false;
|
|
116899
|
-
}
|
|
116900
|
-
if (!plugin.name) {
|
|
116901
|
-
console.error(`Warning: Plugin with no name registering, ignoring.`, plugin);
|
|
116902
|
-
return false;
|
|
116903
|
-
}
|
|
116904
|
-
return true;
|
|
116905
|
-
}
|
|
116906
|
-
/** Error callback in case calling a plugin method throws an error. Can be overwritten. */
|
|
116907
|
-
onPluginError(plugin, method, err) {
|
|
116908
|
-
console.warn(`An error occured while executing "${method}" in plugin "${plugin.name}":`, err);
|
|
116909
|
-
}
|
|
116910
|
-
/**
|
|
116911
|
-
* Define default values for plugins implicitly required through the `dependencies` plugin stanza.
|
|
116912
|
-
*
|
|
116913
|
-
* @param dependencyPath - The string by which the dependency is listed (not the plugin name)
|
|
116914
|
-
*
|
|
116915
|
-
* @example
|
|
116916
|
-
* chromium.use(stealth)
|
|
116917
|
-
* chromium.plugins.setDependencyDefaults('stealth/evasions/webgl.vendor', { vendor: 'Bob', renderer: 'Alice' })
|
|
116918
|
-
*/
|
|
116919
|
-
setDependencyDefaults(dependencyPath, opts) {
|
|
116920
|
-
this._dependencyDefaults.set(dependencyPath, opts);
|
|
116921
|
-
return this;
|
|
116922
|
-
}
|
|
116923
|
-
/**
|
|
116924
|
-
* Define custom plugin modules for plugins implicitly required through the `dependencies` plugin stanza.
|
|
116925
|
-
*
|
|
116926
|
-
* Using this will prevent dynamic imports from being used, which JS bundlers often have issues with.
|
|
116927
|
-
*
|
|
116928
|
-
* @example
|
|
116929
|
-
* chromium.use(stealth)
|
|
116930
|
-
* chromium.plugins.setDependencyResolution('stealth/evasions/webgl.vendor', VendorPlugin)
|
|
116931
|
-
*/
|
|
116932
|
-
setDependencyResolution(dependencyPath, pluginModule) {
|
|
116933
|
-
this._dependencyResolution.set(dependencyPath, pluginModule);
|
|
116934
|
-
return this;
|
|
116935
|
-
}
|
|
116936
|
-
/**
|
|
116937
|
-
* Prepare plugins to be used (resolve dependencies, ordering)
|
|
116938
|
-
* @internal
|
|
116939
|
-
*/
|
|
116940
|
-
prepare() {
|
|
116941
|
-
this.resolveDependencies();
|
|
116942
|
-
this.order();
|
|
116943
|
-
}
|
|
116944
|
-
/** Return all plugins using the supplied method */
|
|
116945
|
-
filterByMethod(methodName) {
|
|
116946
|
-
return this._plugins.filter(plugin => {
|
|
116947
|
-
// PuppeteerExtraPlugin: The base class will already define all methods, hence we need to do a different check
|
|
116948
|
-
if (!!plugin._childClassMembers &&
|
|
116949
|
-
Array.isArray(plugin._childClassMembers)) {
|
|
116950
|
-
return plugin._childClassMembers.includes(methodName);
|
|
116951
|
-
}
|
|
116952
|
-
return methodName in plugin;
|
|
116953
|
-
});
|
|
116954
|
-
}
|
|
116955
|
-
/** Conditionally add puppeteer compatibility to values provided to the plugins */
|
|
116956
|
-
_addPuppeteerCompatIfNeeded(plugin, method, args) {
|
|
116957
|
-
const canUseShim = plugin._isPuppeteerExtraPlugin && !plugin.noPuppeteerShim;
|
|
116958
|
-
const methodWhitelist = [
|
|
116959
|
-
'onBrowser',
|
|
116960
|
-
'onPageCreated',
|
|
116961
|
-
'onPageClose',
|
|
116962
|
-
'afterConnect',
|
|
116963
|
-
'afterLaunch'
|
|
116964
|
-
];
|
|
116965
|
-
const shouldUseShim = methodWhitelist.includes(method);
|
|
116966
|
-
if (!canUseShim || !shouldUseShim) {
|
|
116967
|
-
return args;
|
|
116968
|
-
}
|
|
116969
|
-
debug$1('add puppeteer compatibility', plugin.name, method);
|
|
116970
|
-
return [...args.map(arg => addPuppeteerCompat(arg))];
|
|
116971
|
-
}
|
|
116972
|
-
/**
|
|
116973
|
-
* Dispatch plugin lifecycle events in a typesafe way.
|
|
116974
|
-
* Only Plugins that expose the supplied property will be called.
|
|
116975
|
-
*
|
|
116976
|
-
* Will not await results to dispatch events as fast as possible to all plugins.
|
|
116977
|
-
*
|
|
116978
|
-
* @param method - The lifecycle method name
|
|
116979
|
-
* @param args - Optional: Any arguments to be supplied to the plugin methods
|
|
116980
|
-
* @internal
|
|
116981
|
-
*/
|
|
116982
|
-
dispatch(method, ...args) {
|
|
116983
|
-
var _a, _b;
|
|
116984
|
-
const plugins = this.filterByMethod(method);
|
|
116985
|
-
debug$1('dispatch', method, {
|
|
116986
|
-
all: this._plugins.length,
|
|
116987
|
-
filteredByMethod: plugins.length
|
|
116988
|
-
});
|
|
116989
|
-
for (const plugin of plugins) {
|
|
116990
|
-
try {
|
|
116991
|
-
args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
|
|
116992
|
-
const fnType = (_b = (_a = plugin[method]) === null || _a === void 0 ? void 0 : _a.constructor) === null || _b === void 0 ? void 0 : _b.name;
|
|
116993
|
-
debug$1('dispatch to plugin', {
|
|
116994
|
-
plugin: plugin.name,
|
|
116995
|
-
method,
|
|
116996
|
-
fnType
|
|
116997
|
-
});
|
|
116998
|
-
if (fnType === 'AsyncFunction') {
|
|
116999
|
-
;
|
|
117000
|
-
plugin[method](...args).catch((err) => this.onPluginError(plugin, method, err));
|
|
117001
|
-
}
|
|
117002
|
-
else {
|
|
117003
|
-
;
|
|
117004
|
-
plugin[method](...args);
|
|
117005
|
-
}
|
|
117006
|
-
}
|
|
117007
|
-
catch (err) {
|
|
117008
|
-
this.onPluginError(plugin, method, err);
|
|
117009
|
-
}
|
|
117010
|
-
}
|
|
117011
|
-
}
|
|
117012
|
-
/**
|
|
117013
|
-
* Dispatch plugin lifecycle events in a typesafe way.
|
|
117014
|
-
* Only Plugins that expose the supplied property will be called.
|
|
117015
|
-
*
|
|
117016
|
-
* Can also be used to get a definite return value after passing it to plugins:
|
|
117017
|
-
* Calls plugins sequentially and passes on a value (waterfall style).
|
|
117018
|
-
*
|
|
117019
|
-
* The plugins can either modify the value or return an updated one.
|
|
117020
|
-
* Will return the latest, updated value which ran through all plugins.
|
|
117021
|
-
*
|
|
117022
|
-
* By convention only the first argument will be used as the updated value.
|
|
117023
|
-
*
|
|
117024
|
-
* @param method - The lifecycle method name
|
|
117025
|
-
* @param args - Optional: Any arguments to be supplied to the plugin methods
|
|
117026
|
-
* @internal
|
|
117027
|
-
*/
|
|
117028
|
-
async dispatchBlocking(method, ...args) {
|
|
117029
|
-
const plugins = this.filterByMethod(method);
|
|
117030
|
-
debug$1('dispatchBlocking', method, {
|
|
117031
|
-
all: this._plugins.length,
|
|
117032
|
-
filteredByMethod: plugins.length
|
|
117033
|
-
});
|
|
117034
|
-
let retValue = null;
|
|
117035
|
-
for (const plugin of plugins) {
|
|
117036
|
-
try {
|
|
117037
|
-
args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
|
|
117038
|
-
retValue = await plugin[method](...args);
|
|
117039
|
-
// In case we got a return value use that as new first argument for followup function calls
|
|
117040
|
-
if (retValue !== undefined) {
|
|
117041
|
-
args[0] = retValue;
|
|
117042
|
-
}
|
|
117043
|
-
}
|
|
117044
|
-
catch (err) {
|
|
117045
|
-
this.onPluginError(plugin, method, err);
|
|
117046
|
-
return retValue;
|
|
117047
|
-
}
|
|
117048
|
-
}
|
|
117049
|
-
return retValue;
|
|
117050
|
-
}
|
|
117051
|
-
/**
|
|
117052
|
-
* Order plugins that have expressed a special placement requirement.
|
|
117053
|
-
*
|
|
117054
|
-
* This is useful/necessary for e.g. plugins that depend on the data from other plugins.
|
|
117055
|
-
*
|
|
117056
|
-
* @private
|
|
117057
|
-
*/
|
|
117058
|
-
order() {
|
|
117059
|
-
debug$1('order:before', this.names);
|
|
117060
|
-
const runLast = this._plugins
|
|
117061
|
-
.filter(p => { var _a; return (_a = p.requirements) === null || _a === void 0 ? void 0 : _a.has('runLast'); })
|
|
117062
|
-
.map(p => p.name);
|
|
117063
|
-
for (const name of runLast) {
|
|
117064
|
-
const index = this._plugins.findIndex(p => p.name === name);
|
|
117065
|
-
this._plugins.push(this._plugins.splice(index, 1)[0]);
|
|
117066
|
-
}
|
|
117067
|
-
debug$1('order:after', this.names);
|
|
117068
|
-
}
|
|
117069
|
-
/**
|
|
117070
|
-
* Collects the exposed `data` property of all registered plugins.
|
|
117071
|
-
* Will be reduced/flattened to a single array.
|
|
117072
|
-
*
|
|
117073
|
-
* Can be accessed by plugins that listed the `dataFromPlugins` requirement.
|
|
117074
|
-
*
|
|
117075
|
-
* Implemented mainly for plugins that need data from other plugins (e.g. `user-preferences`).
|
|
117076
|
-
*
|
|
117077
|
-
* @see [PuppeteerExtraPlugin]/data
|
|
117078
|
-
* @param name - Filter data by optional name
|
|
117079
|
-
*
|
|
117080
|
-
* @private
|
|
117081
|
-
*/
|
|
117082
|
-
getData(name) {
|
|
117083
|
-
const data = this._plugins
|
|
117084
|
-
.filter((p) => !!p.data)
|
|
117085
|
-
.map((p) => (Array.isArray(p.data) ? p.data : [p.data]))
|
|
117086
|
-
.reduce((acc, arr) => [...acc, ...arr], []);
|
|
117087
|
-
return name ? data.filter((d) => d.name === name) : data;
|
|
117088
|
-
}
|
|
117089
|
-
/**
|
|
117090
|
-
* Handle `plugins` stanza (already instantiated plugins that don't require dynamic imports)
|
|
117091
|
-
*/
|
|
117092
|
-
resolvePluginsStanza() {
|
|
117093
|
-
debug$1('resolvePluginsStanza');
|
|
117094
|
-
const pluginNames = new Set(this.names);
|
|
117095
|
-
this._plugins
|
|
117096
|
-
.filter(p => !!p.plugins && p.plugins.length)
|
|
117097
|
-
.filter(p => !pluginNames.has(p.name)) // TBD: Do we want to filter out existing?
|
|
117098
|
-
.forEach(parent => {
|
|
117099
|
-
(parent.plugins || []).forEach(p => {
|
|
117100
|
-
debug$1(parent.name, 'adding missing plugin', p.name);
|
|
117101
|
-
this.add(p);
|
|
117102
|
-
});
|
|
117103
|
-
});
|
|
117104
|
-
}
|
|
117105
|
-
/**
|
|
117106
|
-
* Handle `dependencies` stanza (which requires dynamic imports)
|
|
117107
|
-
*
|
|
117108
|
-
* Plugins can define `dependencies` as a Set or Array of dependency paths, or a Map with additional opts
|
|
117109
|
-
*
|
|
117110
|
-
* @note
|
|
117111
|
-
* - The default opts for implicit dependencies can be defined using `setDependencyDefaults()`
|
|
117112
|
-
* - Dynamic imports can be avoided by providing plugin modules with `setDependencyResolution()`
|
|
117113
|
-
*/
|
|
117114
|
-
resolveDependenciesStanza() {
|
|
117115
|
-
debug$1('resolveDependenciesStanza');
|
|
117116
|
-
/** Attempt to dynamically require a plugin module */
|
|
117117
|
-
const requireDependencyOrDie = (parentName, dependencyPath) => {
|
|
117118
|
-
// If the user provided the plugin module already we use that
|
|
117119
|
-
if (this._dependencyResolution.has(dependencyPath)) {
|
|
117120
|
-
return this._dependencyResolution.get(dependencyPath);
|
|
117121
|
-
}
|
|
117122
|
-
const possiblePrefixes = ['puppeteer-extra-plugin-']; // could be extended later
|
|
117123
|
-
const isAlreadyPrefixed = possiblePrefixes.some(prefix => dependencyPath.startsWith(prefix));
|
|
117124
|
-
const packagePaths = [];
|
|
117125
|
-
// If the dependency is not already prefixed we attempt to require all possible combinations to find one that works
|
|
117126
|
-
if (!isAlreadyPrefixed) {
|
|
117127
|
-
packagePaths.push(...possiblePrefixes.map(prefix => prefix + dependencyPath));
|
|
117128
|
-
}
|
|
117129
|
-
// We always attempt to require the path verbatim (as a last resort)
|
|
117130
|
-
packagePaths.push(dependencyPath);
|
|
117131
|
-
const pluginModule = requirePackages(packagePaths);
|
|
117132
|
-
if (pluginModule) {
|
|
117133
|
-
return pluginModule;
|
|
117134
|
-
}
|
|
117135
|
-
const explanation = `
|
|
117136
|
-
The plugin '${parentName}' listed '${dependencyPath}' as dependency,
|
|
117137
|
-
which could not be found. Please install it:
|
|
117138
|
-
|
|
117139
|
-
${packagePaths
|
|
117140
|
-
.map(packagePath => `yarn add ${packagePath.split('/')[0]}`)
|
|
117141
|
-
.join(`\n or:\n`)}
|
|
117142
|
-
|
|
117143
|
-
Note: You don't need to require the plugin yourself,
|
|
117144
|
-
unless you want to modify it's default settings.
|
|
117145
|
-
|
|
117146
|
-
If your bundler has issues with dynamic imports take a look at '.plugins.setDependencyResolution()'.
|
|
117147
|
-
`;
|
|
117148
|
-
console.warn(explanation);
|
|
117149
|
-
throw new Error('Plugin dependency not found');
|
|
117150
|
-
};
|
|
117151
|
-
const existingPluginNames = new Set(this.names);
|
|
117152
|
-
const recursivelyLoadMissingDependencies = ({ name: parentName, dependencies }) => {
|
|
117153
|
-
if (!dependencies) {
|
|
117154
|
-
return;
|
|
117155
|
-
}
|
|
117156
|
-
const processDependency = (dependencyPath, opts) => {
|
|
117157
|
-
const pluginModule = requireDependencyOrDie(parentName, dependencyPath);
|
|
117158
|
-
opts = opts || this._dependencyDefaults.get(dependencyPath) || {};
|
|
117159
|
-
const plugin = pluginModule(opts);
|
|
117160
|
-
if (existingPluginNames.has(plugin.name)) {
|
|
117161
|
-
debug$1(parentName, '=> dependency already exists:', plugin.name);
|
|
117162
|
-
return;
|
|
117163
|
-
}
|
|
117164
|
-
existingPluginNames.add(plugin.name);
|
|
117165
|
-
debug$1(parentName, '=> adding new dependency:', plugin.name, opts);
|
|
117166
|
-
this.add(plugin);
|
|
117167
|
-
return recursivelyLoadMissingDependencies(plugin);
|
|
117168
|
-
};
|
|
117169
|
-
if (dependencies instanceof Set || Array.isArray(dependencies)) {
|
|
117170
|
-
return [...dependencies].forEach(dependencyPath => processDependency(dependencyPath));
|
|
117171
|
-
}
|
|
117172
|
-
if (dependencies instanceof Map) {
|
|
117173
|
-
// Note: `k,v => v,k` (Map + forEach will reverse the order)
|
|
117174
|
-
return dependencies.forEach((v, k) => processDependency(k, v));
|
|
117175
|
-
}
|
|
117176
|
-
};
|
|
117177
|
-
this.list.forEach(recursivelyLoadMissingDependencies);
|
|
117178
|
-
}
|
|
117179
|
-
/**
|
|
117180
|
-
* Lightweight plugin dependency management to require plugins and code mods on demand.
|
|
117181
|
-
* @private
|
|
117182
|
-
*/
|
|
117183
|
-
resolveDependencies() {
|
|
117184
|
-
debug$1('resolveDependencies');
|
|
117185
|
-
this.resolvePluginsStanza();
|
|
117186
|
-
this.resolveDependenciesStanza();
|
|
117187
|
-
}
|
|
117188
|
-
}
|
|
117189
|
-
|
|
117190
|
-
const debug$2 = Debug('playwright-extra');
|
|
117191
|
-
/**
|
|
117192
|
-
* Modular plugin framework to teach `playwright` new tricks.
|
|
117193
|
-
*/
|
|
117194
|
-
class PlaywrightExtraClass {
|
|
117195
|
-
constructor(_launcher) {
|
|
117196
|
-
this._launcher = _launcher;
|
|
117197
|
-
this.plugins = new PluginList();
|
|
117198
|
-
}
|
|
117199
|
-
/**
|
|
117200
|
-
* The **main interface** to register plugins.
|
|
117201
|
-
*
|
|
117202
|
-
* Can be called multiple times to enable multiple plugins.
|
|
117203
|
-
*
|
|
117204
|
-
* Plugins derived from `PuppeteerExtraPlugin` will be used with a compatiblity layer.
|
|
117205
|
-
*
|
|
117206
|
-
* @example
|
|
117207
|
-
* chromium.use(plugin1).use(plugin2)
|
|
117208
|
-
* firefox.use(plugin1).use(plugin2)
|
|
117209
|
-
*
|
|
117210
|
-
* @see [PuppeteerExtraPlugin]
|
|
117211
|
-
*
|
|
117212
|
-
* @return The same `PlaywrightExtra` instance (for optional chaining)
|
|
117213
|
-
*/
|
|
117214
|
-
use(plugin) {
|
|
117215
|
-
const isValid = plugin && 'name' in plugin;
|
|
117216
|
-
if (!isValid) {
|
|
117217
|
-
throw new Error('A plugin must be provided to .use()');
|
|
117218
|
-
}
|
|
117219
|
-
if (this.plugins.add(plugin)) {
|
|
117220
|
-
debug$2('Plugin registered', plugin.name);
|
|
117221
|
-
}
|
|
117222
|
-
return this;
|
|
117223
|
-
}
|
|
117224
|
-
/**
|
|
117225
|
-
* In order to support a default export which will require vanilla playwright automatically,
|
|
117226
|
-
* as well as `addExtra` to patch a provided launcher, we need to so some gymnastics here.
|
|
117227
|
-
*
|
|
117228
|
-
* Otherwise this would throw immediately, even when only using the `addExtra` export with an arbitrary compatible launcher.
|
|
117229
|
-
*
|
|
117230
|
-
* The solution is to make the vanilla launcher optional and only throw once we try to effectively use and can't find it.
|
|
117231
|
-
*
|
|
117232
|
-
* @internal
|
|
117233
|
-
*/
|
|
117234
|
-
get launcher() {
|
|
117235
|
-
if (!this._launcher) {
|
|
117236
|
-
throw playwrightLoader.requireError;
|
|
117237
|
-
}
|
|
117238
|
-
return this._launcher;
|
|
117239
|
-
}
|
|
117240
|
-
async launch(...args) {
|
|
117241
|
-
if (!this.launcher.launch) {
|
|
117242
|
-
throw new Error('Launcher does not support "launch"');
|
|
117243
|
-
}
|
|
117244
|
-
let [options] = args;
|
|
117245
|
-
options = Object.assign({ args: [] }, (options || {})); // Initialize args array
|
|
117246
|
-
debug$2('launch', options);
|
|
117247
|
-
this.plugins.prepare();
|
|
117248
|
-
// Give plugins the chance to modify the options before continuing
|
|
117249
|
-
options =
|
|
117250
|
-
(await this.plugins.dispatchBlocking('beforeLaunch', options)) || options;
|
|
117251
|
-
debug$2('launch with options', options);
|
|
117252
|
-
if ('userDataDir' in options) {
|
|
117253
|
-
debug$2("A plugin defined userDataDir during .launch, which isn't supported by playwright - ignoring");
|
|
117254
|
-
delete options.userDataDir;
|
|
117255
|
-
}
|
|
117256
|
-
const browser = await this.launcher['launch'](options);
|
|
117257
|
-
await this.plugins.dispatchBlocking('onBrowser', browser);
|
|
117258
|
-
await this._bindBrowserEvents(browser);
|
|
117259
|
-
await this.plugins.dispatchBlocking('afterLaunch', browser);
|
|
117260
|
-
return browser;
|
|
117261
|
-
}
|
|
117262
|
-
async launchPersistentContext(...args) {
|
|
117263
|
-
if (!this.launcher.launchPersistentContext) {
|
|
117264
|
-
throw new Error('Launcher does not support "launchPersistentContext"');
|
|
117265
|
-
}
|
|
117266
|
-
let [userDataDir, options] = args;
|
|
117267
|
-
options = Object.assign({ args: [] }, (options || {})); // Initialize args array
|
|
117268
|
-
debug$2('launchPersistentContext', options);
|
|
117269
|
-
this.plugins.prepare();
|
|
117270
|
-
// Give plugins the chance to modify the options before continuing
|
|
117271
|
-
options =
|
|
117272
|
-
(await this.plugins.dispatchBlocking('beforeLaunch', options)) || options;
|
|
117273
|
-
const context = await this.launcher['launchPersistentContext'](userDataDir, options);
|
|
117274
|
-
await this.plugins.dispatchBlocking('afterLaunch', context);
|
|
117275
|
-
this._bindBrowserContextEvents(context);
|
|
117276
|
-
return context;
|
|
117277
|
-
}
|
|
117278
|
-
async connect(wsEndpointOrOptions, wsOptions = {}) {
|
|
117279
|
-
if (!this.launcher.connect) {
|
|
117280
|
-
throw new Error('Launcher does not support "connect"');
|
|
117281
|
-
}
|
|
117282
|
-
this.plugins.prepare();
|
|
117283
|
-
// Playwright currently supports two function signatures for .connect
|
|
117284
|
-
let options = {};
|
|
117285
|
-
let wsEndpointAsString = false;
|
|
117286
|
-
if (typeof wsEndpointOrOptions === 'object') {
|
|
117287
|
-
options = Object.assign(Object.assign({}, wsEndpointOrOptions), wsOptions);
|
|
117288
|
-
}
|
|
117289
|
-
else {
|
|
117290
|
-
wsEndpointAsString = true;
|
|
117291
|
-
options = Object.assign({ wsEndpoint: wsEndpointOrOptions }, wsOptions);
|
|
117292
|
-
}
|
|
117293
|
-
debug$2('connect', options);
|
|
117294
|
-
// Give plugins the chance to modify the options before launch/connect
|
|
117295
|
-
options =
|
|
117296
|
-
(await this.plugins.dispatchBlocking('beforeConnect', options)) || options;
|
|
117297
|
-
// Follow call signature of end user
|
|
117298
|
-
const args = [];
|
|
117299
|
-
const wsEndpoint = options.wsEndpoint;
|
|
117300
|
-
if (wsEndpointAsString) {
|
|
117301
|
-
delete options.wsEndpoint;
|
|
117302
|
-
args.push(wsEndpoint, options);
|
|
117303
|
-
}
|
|
117304
|
-
else {
|
|
117305
|
-
args.push(options);
|
|
117306
|
-
}
|
|
117307
|
-
const browser = (await this.launcher['connect'](...args));
|
|
117308
|
-
await this.plugins.dispatchBlocking('onBrowser', browser);
|
|
117309
|
-
await this._bindBrowserEvents(browser);
|
|
117310
|
-
await this.plugins.dispatchBlocking('afterConnect', browser);
|
|
117311
|
-
return browser;
|
|
117312
|
-
}
|
|
117313
|
-
async connectOverCDP(wsEndpointOrOptions, wsOptions = {}) {
|
|
117314
|
-
if (!this.launcher.connectOverCDP) {
|
|
117315
|
-
throw new Error(`Launcher does not implement 'connectOverCDP'`);
|
|
117316
|
-
}
|
|
117317
|
-
this.plugins.prepare();
|
|
117318
|
-
// Playwright currently supports two function signatures for .connectOverCDP
|
|
117319
|
-
let options = {};
|
|
117320
|
-
let wsEndpointAsString = false;
|
|
117321
|
-
if (typeof wsEndpointOrOptions === 'object') {
|
|
117322
|
-
options = Object.assign(Object.assign({}, wsEndpointOrOptions), wsOptions);
|
|
117323
|
-
}
|
|
117324
|
-
else {
|
|
117325
|
-
wsEndpointAsString = true;
|
|
117326
|
-
options = Object.assign({ endpointURL: wsEndpointOrOptions }, wsOptions);
|
|
117327
|
-
}
|
|
117328
|
-
debug$2('connectOverCDP');
|
|
117329
|
-
// Give plugins the chance to modify the options before launch/connect
|
|
117330
|
-
options =
|
|
117331
|
-
(await this.plugins.dispatchBlocking('beforeConnect', options)) || options;
|
|
117332
|
-
// Follow call signature of end user
|
|
117333
|
-
const args = [];
|
|
117334
|
-
const endpointURL = options.endpointURL;
|
|
117335
|
-
if (wsEndpointAsString) {
|
|
117336
|
-
delete options.endpointURL;
|
|
117337
|
-
args.push(endpointURL, options);
|
|
117338
|
-
}
|
|
117339
|
-
else {
|
|
117340
|
-
args.push(options);
|
|
117341
|
-
}
|
|
117342
|
-
const browser = (await this.launcher['connectOverCDP'](...args));
|
|
117343
|
-
await this.plugins.dispatchBlocking('onBrowser', browser);
|
|
117344
|
-
await this._bindBrowserEvents(browser);
|
|
117345
|
-
await this.plugins.dispatchBlocking('afterConnect', browser);
|
|
117346
|
-
return browser;
|
|
117347
|
-
}
|
|
117348
|
-
async _bindBrowserContextEvents(context, contextOptions) {
|
|
117349
|
-
debug$2('_bindBrowserContextEvents');
|
|
117350
|
-
this.plugins.dispatch('onContextCreated', context, contextOptions);
|
|
117351
|
-
// Make sure things like `addInitScript` show an effect on the very first page as well
|
|
117352
|
-
context.newPage = ((originalMethod, ctx) => {
|
|
117353
|
-
return async () => {
|
|
117354
|
-
const page = await originalMethod.call(ctx);
|
|
117355
|
-
await page.goto('about:blank');
|
|
117356
|
-
return page;
|
|
117357
|
-
};
|
|
117358
|
-
})(context.newPage, context);
|
|
117359
|
-
context.on('close', () => {
|
|
117360
|
-
// When using `launchPersistentContext` context closing is the same as browser closing
|
|
117361
|
-
if (!context.browser()) {
|
|
117362
|
-
this.plugins.dispatch('onDisconnected');
|
|
117363
|
-
}
|
|
117364
|
-
});
|
|
117365
|
-
context.on('page', page => {
|
|
117366
|
-
this.plugins.dispatch('onPageCreated', page);
|
|
117367
|
-
page.on('close', () => {
|
|
117368
|
-
this.plugins.dispatch('onPageClose', page);
|
|
117369
|
-
});
|
|
117370
|
-
});
|
|
117371
|
-
}
|
|
117372
|
-
async _bindBrowserEvents(browser) {
|
|
117373
|
-
debug$2('_bindPlaywrightBrowserEvents');
|
|
117374
|
-
browser.on('disconnected', () => {
|
|
117375
|
-
this.plugins.dispatch('onDisconnected', browser);
|
|
117376
|
-
});
|
|
117377
|
-
// Note: `browser.newPage` will implicitly call `browser.newContext` as well
|
|
117378
|
-
browser.newContext = ((originalMethod, ctx) => {
|
|
117379
|
-
return async (options = {}) => {
|
|
117380
|
-
const contextOptions = (await this.plugins.dispatchBlocking('beforeContext', options, browser)) || options;
|
|
117381
|
-
const context = await originalMethod.call(ctx, contextOptions);
|
|
117382
|
-
this._bindBrowserContextEvents(context, contextOptions);
|
|
117383
|
-
return context;
|
|
117384
|
-
};
|
|
117385
|
-
})(browser.newContext, browser);
|
|
117386
|
-
}
|
|
117387
|
-
}
|
|
117388
|
-
/**
|
|
117389
|
-
* PlaywrightExtra class with additional launcher methods.
|
|
117390
|
-
*
|
|
117391
|
-
* Augments the class with an instance proxy to pass on methods that are not augmented to the original target.
|
|
117392
|
-
*
|
|
117393
|
-
*/
|
|
117394
|
-
const PlaywrightExtra = new Proxy(PlaywrightExtraClass, {
|
|
117395
|
-
construct(classTarget, args) {
|
|
117396
|
-
debug$2(`create instance of ${classTarget.name}`);
|
|
117397
|
-
const result = Reflect.construct(classTarget, args);
|
|
117398
|
-
return new Proxy(result, {
|
|
117399
|
-
get(target, prop) {
|
|
117400
|
-
if (prop in target) {
|
|
117401
|
-
return Reflect.get(target, prop);
|
|
117402
|
-
}
|
|
117403
|
-
debug$2('proxying property to original launcher: ', prop);
|
|
117404
|
-
return Reflect.get(target.launcher, prop);
|
|
117405
|
-
}
|
|
117406
|
-
});
|
|
117407
|
-
}
|
|
117408
|
-
});
|
|
117409
|
-
|
|
117410
|
-
/**
|
|
117411
|
-
* Augment the provided Playwright browser launcher with plugin functionality.
|
|
117412
|
-
*
|
|
117413
|
-
* Using `addExtra` will always create a fresh PlaywrightExtra instance.
|
|
117414
|
-
*
|
|
117415
|
-
* @example
|
|
117416
|
-
* import playwright from 'playwright'
|
|
117417
|
-
* import { addExtra } from 'playwright-extra'
|
|
117418
|
-
*
|
|
117419
|
-
* const chromium = addExtra(playwright.chromium)
|
|
117420
|
-
* chromium.use(plugin)
|
|
117421
|
-
*
|
|
117422
|
-
* @param launcher - Playwright (or compatible) browser launcher
|
|
117423
|
-
*/
|
|
117424
|
-
const addExtra = (launcher) => new PlaywrightExtra(launcher);
|
|
117425
|
-
/**
|
|
117426
|
-
* This object can be used to launch or connect to Chromium with plugin functionality.
|
|
117427
|
-
*
|
|
117428
|
-
* This default export will behave exactly the same as the regular playwright
|
|
117429
|
-
* (just with extra plugin functionality) and can be used as a drop-in replacement.
|
|
117430
|
-
*
|
|
117431
|
-
* Behind the scenes it will try to require either the `playwright-core`
|
|
117432
|
-
* or `playwright` module from the installed dependencies.
|
|
117433
|
-
*
|
|
117434
|
-
* @note
|
|
117435
|
-
* Due to Node.js import caching this will result in a single
|
|
117436
|
-
* PlaywrightExtra instance, even when used in different files. If you need multiple
|
|
117437
|
-
* instances with different plugins please use `addExtra`.
|
|
117438
|
-
*
|
|
117439
|
-
* @example
|
|
117440
|
-
* // javascript import
|
|
117441
|
-
* const { chromium } = require('playwright-extra')
|
|
117442
|
-
*
|
|
117443
|
-
* // typescript/es6 module import
|
|
117444
|
-
* import { chromium } from 'playwright-extra'
|
|
117445
|
-
*
|
|
117446
|
-
* // Add plugins
|
|
117447
|
-
* chromium.use(...)
|
|
117448
|
-
*/
|
|
117449
|
-
const chromium = addExtra((playwrightLoader.loadModule() || {}).chromium);
|
|
117450
|
-
/**
|
|
117451
|
-
* This object can be used to launch or connect to Firefox with plugin functionality
|
|
117452
|
-
* @note This export will always return the same instance, if you wish to use multiple instances with different plugins use `addExtra`
|
|
117453
|
-
*/
|
|
117454
|
-
addExtra((playwrightLoader.loadModule() || {}).firefox);
|
|
117455
|
-
/**
|
|
117456
|
-
* This object can be used to launch or connect to Webkit with plugin functionality
|
|
117457
|
-
* @note This export will always return the same instance, if you wish to use multiple instances with different plugins use `addExtra`
|
|
117458
|
-
*/
|
|
117459
|
-
addExtra((playwrightLoader.loadModule() || {}).webkit);
|
|
117460
|
-
// Other playwright module exports we simply re-export with lazy loading
|
|
117461
|
-
playwrightLoader.lazyloadExportOrDie('_android');
|
|
117462
|
-
playwrightLoader.lazyloadExportOrDie('_electron');
|
|
117463
|
-
playwrightLoader.lazyloadExportOrDie('request');
|
|
117464
|
-
playwrightLoader.lazyloadExportOrDie('selectors');
|
|
117465
|
-
playwrightLoader.lazyloadExportOrDie('devices');
|
|
117466
|
-
playwrightLoader.lazyloadExportOrDie('errors');
|
|
117467
|
-
|
|
117468
116576
|
var stealth = test$1.extend({
|
|
117469
|
-
browser: async ({
|
|
117470
|
-
|
|
117471
|
-
|
|
117472
|
-
const stealthBrowser = await
|
|
116577
|
+
browser: async ({}, use) => {
|
|
116578
|
+
const chromiumBrowser = addExtra(chromium);
|
|
116579
|
+
chromiumBrowser.use(stealth$1());
|
|
116580
|
+
const stealthBrowser = await chromiumBrowser.launch();
|
|
117473
116581
|
await use(stealthBrowser);
|
|
117474
116582
|
await stealthBrowser.close();
|
|
117475
116583
|
},
|
|
@@ -117569,7 +116677,7 @@ const i18nFixture = {
|
|
|
117569
116677
|
i18n: [
|
|
117570
116678
|
async ({}, use) => {
|
|
117571
116679
|
const translation = readTranslations();
|
|
117572
|
-
const page = await (await chromium
|
|
116680
|
+
const page = await (await chromium.launch()).newPage();
|
|
117573
116681
|
const taxonomies = await mergeTaxonomies(translation, page);
|
|
117574
116682
|
const options = {
|
|
117575
116683
|
debug: false,
|
|
@@ -125760,7 +124868,7 @@ async function warmup({ urls = DEFAULT_WARMUP_URLS, timeout = 60_000, } = {}) {
|
|
|
125760
124868
|
throw new Error("RAILS_SERVER_PORT is not defined in environment variables.");
|
|
125761
124869
|
}
|
|
125762
124870
|
const baseURL = `http://${SUBDOMAIN}.lvh.me:${RAILS_SERVER_PORT}`;
|
|
125763
|
-
const browser = await chromium
|
|
124871
|
+
const browser = await chromium.launch();
|
|
125764
124872
|
const page = await browser.newPage();
|
|
125765
124873
|
try {
|
|
125766
124874
|
for (const url of urls) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-playwright-commons",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "A package encapsulating common playwright code across neeto projects.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-playwright-commons.git",
|
|
6
6
|
"license": "apache-2.0",
|
|
@@ -65,7 +65,6 @@
|
|
|
65
65
|
"nano-staged": "^1.0.2",
|
|
66
66
|
"octokit": "^5.0.5",
|
|
67
67
|
"prettier": "3.8.1",
|
|
68
|
-
"puppeteer-extra-plugin-stealth": "2.11.2",
|
|
69
68
|
"ramda": "0.32.0",
|
|
70
69
|
"remark-parse": "11.0.0",
|
|
71
70
|
"rollup": "^4.60.1",
|
|
@@ -83,7 +82,6 @@
|
|
|
83
82
|
"i18next": "25.8.14",
|
|
84
83
|
"octokit": "^5.0.5",
|
|
85
84
|
"playwright-i18next-fixture": "1.0.0",
|
|
86
|
-
"puppeteer-extra-plugin-stealth": "2.11.2",
|
|
87
85
|
"ramda": "0.32.0"
|
|
88
86
|
},
|
|
89
87
|
"dependencies": {
|
|
@@ -99,7 +97,8 @@
|
|
|
99
97
|
"otpauth": "9.5.0",
|
|
100
98
|
"picoquery": "^2.5.0",
|
|
101
99
|
"playwright-extra": "4.3.6",
|
|
102
|
-
"playwright-i18next-fixture": "1.0.0"
|
|
100
|
+
"playwright-i18next-fixture": "1.0.0",
|
|
101
|
+
"puppeteer-extra-plugin-stealth": "2.11.2"
|
|
103
102
|
},
|
|
104
103
|
"packageManager": "yarn@4.13.0"
|
|
105
104
|
}
|