@zorilla/playwright-extra 1.0.0

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE3C,OAAO,EAAmB,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,oCAAoC;AACpC,MAAM,MAAM,yBAAyB,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;AAC3D,8DAA8D;AAC9D,MAAM,MAAM,wBAAwB,GAAG,oBAAoB,GACzD,yBAAyB,CAAC;AAE5B;;;GAGG;AACH,MAAM,WAAW,4BAA4B;IAC3C,OAAO,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IAClD,MAAM,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;IACjD,uBAAuB,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC;IACzE,cAAc,CAAC,CAAC,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;CAC1D;AAgBD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ,GAAI,QAAQ,SAAS,4BAA4B,EACpE,WAAW,QAAQ,KACiB,oBAAoB,GAAG,QAAQ,CAAC;AAEtE;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8DJ,CAAC;AAElE,eAAe,aAAa,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,80 @@
1
+ import { PlaywrightExtra, PlaywrightExtraClass } from './extra.js';
2
+ import { playwrightLoader as loader } from './helper/loader.js';
3
+ import { PluginList } from './plugins.js';
4
+ export { PlaywrightExtra, PlaywrightExtraClass } from './extra.js';
5
+ export { PluginList } from './plugins.js';
6
+ /**
7
+ * Augment the provided Playwright browser launcher with plugin functionality.
8
+ *
9
+ * Using `addExtra` will always create a fresh PlaywrightExtra instance.
10
+ *
11
+ * @example
12
+ * import playwright from 'playwright'
13
+ * import { addExtra } from '@zorilla/playwright-extra'
14
+ *
15
+ * const chromium = addExtra(playwright.chromium)
16
+ * chromium.use(plugin)
17
+ *
18
+ * @param launcher - Playwright (or compatible) browser launcher
19
+ */
20
+ export const addExtra = (launcher) => new PlaywrightExtra(launcher);
21
+ /**
22
+ * This object can be used to launch or connect to Chromium with plugin functionality.
23
+ *
24
+ * This default export will behave exactly the same as the regular playwright
25
+ * (just with extra plugin functionality) and can be used as a drop-in replacement.
26
+ *
27
+ * Behind the scenes it will try to require either the `playwright-core`
28
+ * or `playwright` module from the installed dependencies.
29
+ *
30
+ * @note
31
+ * Due to Node.js import caching this will result in a single
32
+ * PlaywrightExtra instance, even when used in different files. If you need multiple
33
+ * instances with different plugins please use `addExtra`.
34
+ *
35
+ * @example
36
+ * // javascript import
37
+ * // ESM import
38
+ * import { chromium } from '@zorilla/playwright-extra'
39
+ *
40
+ * // Add plugins
41
+ * chromium.use(...)
42
+ */
43
+ export const chromium = addExtra(loader.loadModule()?.chromium);
44
+ /**
45
+ * This object can be used to launch or connect to Firefox with plugin functionality
46
+ * @note This export will always return the same instance, if you wish to use multiple instances with different plugins use `addExtra`
47
+ */
48
+ export const firefox = addExtra(loader.loadModule()?.firefox);
49
+ /**
50
+ * This object can be used to launch or connect to Webkit with plugin functionality
51
+ * @note This export will always return the same instance, if you wish to use multiple instances with different plugins use `addExtra`
52
+ */
53
+ export const webkit = addExtra(loader.loadModule()?.webkit);
54
+ // Other playwright module exports we simply re-export with lazy loading
55
+ export const _android = loader.lazyloadExportOrDie('_android');
56
+ export const _electron = loader.lazyloadExportOrDie('_electron');
57
+ export const request = loader.lazyloadExportOrDie('request');
58
+ export const selectors = loader.lazyloadExportOrDie('selectors');
59
+ export const devices = loader.lazyloadExportOrDie('devices');
60
+ export const errors = loader.lazyloadExportOrDie('errors');
61
+ /** Playwright with plugin functionality */
62
+ const moduleExports = {
63
+ // custom exports
64
+ PlaywrightExtra,
65
+ PlaywrightExtraClass,
66
+ PluginList,
67
+ addExtra,
68
+ chromium,
69
+ firefox,
70
+ webkit,
71
+ // vanilla exports
72
+ _android,
73
+ _electron,
74
+ request,
75
+ selectors,
76
+ devices,
77
+ errors,
78
+ };
79
+ export default moduleExports;
80
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,gBAAgB,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAiC1C;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CACtB,QAAmB,EACnB,EAAE,CAAC,IAAI,eAAe,CAAC,QAAQ,CAAoC,CAAC;AAEtE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,QAAQ,CAAC,CAAC;AAChE;;;GAGG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;AAC9D;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,EAAE,MAAM,CAAC,CAAC;AAE5D,wEAAwE;AACxE,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,mBAAmB,CAAC,UAAU,CAAC,CAAC;AAC/D,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC,WAAW,CAAC,CAAC;AACjE,MAAM,CAAC,MAAM,OAAO,GAAG,MAAM,CAAC,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAC7D,MAAM,CAAC,MAAM,MAAM,GAAG,MAAM,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAE3D,2CAA2C;AAC3C,MAAM,aAAa,GAAG;IACpB,iBAAiB;IACjB,eAAe;IACf,oBAAoB;IACpB,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,MAAM;IAEN,kBAAkB;IAClB,QAAQ;IACR,SAAS;IACT,OAAO;IACP,SAAS;IACT,OAAO;IACP,MAAM;CACyD,CAAC;AAElE,eAAe,aAAa,CAAC"}
@@ -0,0 +1,84 @@
1
+ import type { CompatiblePluginModule, Plugin, PluginMethodFn, PluginMethodName } from './types/index.js';
2
+ export declare class PluginList {
3
+ private readonly _plugins;
4
+ private readonly _dependencyDefaults;
5
+ private readonly _dependencyResolution;
6
+ /**
7
+ * Get a list of all registered plugins.
8
+ */
9
+ get list(): import("./types/index.js").PuppeteerExtraPlugin[];
10
+ /**
11
+ * Get the names of all registered plugins.
12
+ */
13
+ get names(): string[];
14
+ /** Check if the shape of a plugin is correct or warn */
15
+ protected isValidPluginInstance(plugin: Plugin): boolean;
16
+ /** Error callback in case calling a plugin method throws an error. Can be overwritten. */
17
+ onPluginError(plugin: Plugin, method: PluginMethodName, err: Error): void;
18
+ /**
19
+ * Define default values for plugins implicitly required through the `dependencies` plugin stanza.
20
+ *
21
+ * @param dependencyPath - The string by which the dependency is listed (not the plugin name)
22
+ *
23
+ * @example
24
+ * chromium.use(stealth)
25
+ * chromium.plugins.setDependencyDefaults('stealth/evasions/webgl.vendor', { vendor: 'Bob', renderer: 'Alice' })
26
+ */
27
+ setDependencyDefaults(dependencyPath: string, opts: unknown): this;
28
+ /**
29
+ * Define custom plugin modules for plugins implicitly required through the `dependencies` plugin stanza.
30
+ *
31
+ * Using this will prevent dynamic imports from being used, which JS bundlers often have issues with.
32
+ *
33
+ * @example
34
+ * chromium.use(stealth)
35
+ * chromium.plugins.setDependencyResolution('stealth/evasions/webgl.vendor', VendorPlugin)
36
+ */
37
+ setDependencyResolution(dependencyPath: string, pluginModule: CompatiblePluginModule): this;
38
+ /** Return all plugins using the supplied method */
39
+ protected filterByMethod(methodName: PluginMethodName): import("./types/index.js").PuppeteerExtraPlugin[];
40
+ /** Conditionally add puppeteer compatibility to values provided to the plugins */
41
+ protected _addPuppeteerCompatIfNeeded<TMethod extends PluginMethodName>(plugin: Plugin, method: TMethod, args: Parameters<PluginMethodFn<TMethod>>): Parameters<PluginMethodFn<TMethod>>;
42
+ /**
43
+ * Order plugins that have expressed a special placement requirement.
44
+ *
45
+ * This is useful/necessary for e.g. plugins that depend on the data from other plugins.
46
+ *
47
+ * @private
48
+ */
49
+ protected order(): void;
50
+ /**
51
+ * Collects the exposed `data` property of all registered plugins.
52
+ * Will be reduced/flattened to a single array.
53
+ *
54
+ * Can be accessed by plugins that listed the `dataFromPlugins` requirement.
55
+ *
56
+ * Implemented mainly for plugins that need data from other plugins (e.g. `user-preferences`).
57
+ *
58
+ * @see [PuppeteerExtraPlugin]/data
59
+ * @param name - Filter data by optional name
60
+ *
61
+ * @private
62
+ */
63
+ protected getData(name?: string): unknown[];
64
+ /**
65
+ * Handle `plugins` stanza (already instantiated plugins that don't require dynamic imports)
66
+ */
67
+ protected resolvePluginsStanza(): void;
68
+ /**
69
+ * Handle `dependencies` stanza (which requires dynamic imports)
70
+ *
71
+ * Plugins can define `dependencies` as a Set or Array of dependency paths, or a Map with additional opts
72
+ *
73
+ * @note
74
+ * - The default opts for implicit dependencies can be defined using `setDependencyDefaults()`
75
+ * - Dynamic imports can be avoided by providing plugin modules with `setDependencyResolution()`
76
+ */
77
+ protected resolveDependenciesStanza(): void;
78
+ /**
79
+ * Lightweight plugin dependency management to require plugins and code mods on demand.
80
+ * @private
81
+ */
82
+ protected resolveDependencies(): void;
83
+ }
84
+ //# sourceMappingURL=plugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.d.ts","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,sBAAsB,EACtB,MAAM,EACN,cAAc,EACd,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAE1B,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgB;IACzC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAAmC;IACvE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAC1B;IAEZ;;OAEG;IACH,IAAW,IAAI,sDAEd;IAED;;OAEG;IACH,IAAW,KAAK,aAEf;IA0BD,wDAAwD;IACxD,SAAS,CAAC,qBAAqB,CAAC,MAAM,EAAE,MAAM;IAsB9C,0FAA0F;IACnF,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAG,EAAE,KAAK;IAOzE;;;;;;;;OAQG;IACI,qBAAqB,CAAC,cAAc,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;IAKlE;;;;;;;;OAQG;IACI,uBAAuB,CAC5B,cAAc,EAAE,MAAM,EACtB,YAAY,EAAE,sBAAsB;IAetC,mDAAmD;IACnD,SAAS,CAAC,cAAc,CAAC,UAAU,EAAE,gBAAgB;IAarD,kFAAkF;IAClF,SAAS,CAAC,2BAA2B,CAAC,OAAO,SAAS,gBAAgB,EACpE,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,OAAO,EACf,IAAI,EAAE,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IAyI3C;;;;;;OAMG;IACH,SAAS,CAAC,KAAK;IAiBf;;;;;;;;;;;;OAYG;IACH,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,MAAM;IAgB/B;;OAEG;IACH,SAAS,CAAC,oBAAoB;IAc9B;;;;;;;;OAQG;IACH,SAAS,CAAC,yBAAyB;IAsFnC;;;OAGG;IACH,SAAS,CAAC,mBAAmB;CAK9B"}
@@ -0,0 +1,363 @@
1
+ import Debug from 'debug';
2
+ const debug = Debug('playwright-extra:plugins');
3
+ import { requirePackages } from './helper/loader.js';
4
+ import { addPuppeteerCompat } from './puppeteer-compatiblity-shim/index.js';
5
+ export class PluginList {
6
+ _plugins = [];
7
+ _dependencyDefaults = new Map();
8
+ _dependencyResolution = new Map();
9
+ /**
10
+ * Get a list of all registered plugins.
11
+ */
12
+ get list() {
13
+ return this._plugins;
14
+ }
15
+ /**
16
+ * Get the names of all registered plugins.
17
+ */
18
+ get names() {
19
+ return this._plugins.map(p => p.name);
20
+ }
21
+ /**
22
+ * Add a new plugin to the list (after checking if it's well-formed).
23
+ *
24
+ * @param plugin
25
+ * @internal
26
+ */
27
+ add(plugin) {
28
+ if (!this.isValidPluginInstance(plugin)) {
29
+ return false;
30
+ }
31
+ if (plugin.onPluginRegistered) {
32
+ plugin.onPluginRegistered({ framework: 'playwright' });
33
+ }
34
+ // PuppeteerExtraPlugin: Populate `_childClassMembers` list containing methods defined by the plugin
35
+ if (plugin._registerChildClassMembers) {
36
+ plugin._registerChildClassMembers(Object.getPrototypeOf(plugin));
37
+ }
38
+ if (plugin.requirements?.has('dataFromPlugins')) {
39
+ plugin.getDataFromPlugins = this.getData.bind(this);
40
+ }
41
+ this._plugins.push(plugin);
42
+ return true;
43
+ }
44
+ /** Check if the shape of a plugin is correct or warn */
45
+ isValidPluginInstance(plugin) {
46
+ if (!plugin ||
47
+ typeof plugin !== 'object' ||
48
+ !plugin._isPuppeteerExtraPlugin) {
49
+ console.error(`Warning: Plugin is not derived from PuppeteerExtraPlugin, ignoring.`, plugin);
50
+ return false;
51
+ }
52
+ if (!plugin.name) {
53
+ console.error(`Warning: Plugin with no name registering, ignoring.`, plugin);
54
+ return false;
55
+ }
56
+ return true;
57
+ }
58
+ /** Error callback in case calling a plugin method throws an error. Can be overwritten. */
59
+ onPluginError(plugin, method, err) {
60
+ console.warn(`An error occured while executing "${method}" in plugin "${plugin.name}":`, err);
61
+ }
62
+ /**
63
+ * Define default values for plugins implicitly required through the `dependencies` plugin stanza.
64
+ *
65
+ * @param dependencyPath - The string by which the dependency is listed (not the plugin name)
66
+ *
67
+ * @example
68
+ * chromium.use(stealth)
69
+ * chromium.plugins.setDependencyDefaults('stealth/evasions/webgl.vendor', { vendor: 'Bob', renderer: 'Alice' })
70
+ */
71
+ setDependencyDefaults(dependencyPath, opts) {
72
+ this._dependencyDefaults.set(dependencyPath, opts);
73
+ return this;
74
+ }
75
+ /**
76
+ * Define custom plugin modules for plugins implicitly required through the `dependencies` plugin stanza.
77
+ *
78
+ * Using this will prevent dynamic imports from being used, which JS bundlers often have issues with.
79
+ *
80
+ * @example
81
+ * chromium.use(stealth)
82
+ * chromium.plugins.setDependencyResolution('stealth/evasions/webgl.vendor', VendorPlugin)
83
+ */
84
+ setDependencyResolution(dependencyPath, pluginModule) {
85
+ this._dependencyResolution.set(dependencyPath, pluginModule);
86
+ return this;
87
+ }
88
+ /**
89
+ * Prepare plugins to be used (resolve dependencies, ordering)
90
+ * @internal
91
+ */
92
+ prepare() {
93
+ this.resolveDependencies();
94
+ this.order();
95
+ }
96
+ /** Return all plugins using the supplied method */
97
+ filterByMethod(methodName) {
98
+ return this._plugins.filter(plugin => {
99
+ // PuppeteerExtraPlugin: The base class will already define all methods, hence we need to do a different check
100
+ if (!!plugin._childClassMembers &&
101
+ Array.isArray(plugin._childClassMembers)) {
102
+ return plugin._childClassMembers.includes(methodName);
103
+ }
104
+ return methodName in plugin;
105
+ });
106
+ }
107
+ /** Conditionally add puppeteer compatibility to values provided to the plugins */
108
+ _addPuppeteerCompatIfNeeded(plugin, method, args) {
109
+ const canUseShim = plugin._isPuppeteerExtraPlugin && !plugin.noPuppeteerShim;
110
+ const methodWhitelist = [
111
+ 'onBrowser',
112
+ 'onPageCreated',
113
+ 'onPageClose',
114
+ 'afterConnect',
115
+ 'afterLaunch',
116
+ ];
117
+ const shouldUseShim = methodWhitelist.includes(method);
118
+ if (!canUseShim || !shouldUseShim) {
119
+ return args;
120
+ }
121
+ debug('add puppeteer compatibility', plugin.name, method);
122
+ return [
123
+ ...args.map(arg => addPuppeteerCompat(arg)),
124
+ ];
125
+ }
126
+ /**
127
+ * Dispatch plugin lifecycle events in a typesafe way.
128
+ * Only Plugins that expose the supplied property will be called.
129
+ *
130
+ * Will not await results to dispatch events as fast as possible to all plugins.
131
+ *
132
+ * @param method - The lifecycle method name
133
+ * @param args - Optional: Any arguments to be supplied to the plugin methods
134
+ * @internal
135
+ */
136
+ dispatch(method, ...args) {
137
+ const plugins = this.filterByMethod(method);
138
+ debug('dispatch', method, {
139
+ all: this._plugins.length,
140
+ filteredByMethod: plugins.length,
141
+ });
142
+ for (const plugin of plugins) {
143
+ try {
144
+ args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
145
+ const fnType = plugin[method]?.constructor?.name;
146
+ debug('dispatch to plugin', {
147
+ plugin: plugin.name,
148
+ method,
149
+ fnType,
150
+ });
151
+ if (fnType === 'AsyncFunction') {
152
+ const asyncMethod = plugin[method];
153
+ asyncMethod
154
+ .call(plugin, ...args)
155
+ .catch((err) => this.onPluginError(plugin, method, err instanceof Error ? err : new Error(String(err))));
156
+ }
157
+ else {
158
+ const syncMethod = plugin[method];
159
+ syncMethod.call(plugin, ...args);
160
+ }
161
+ }
162
+ catch (err) {
163
+ this.onPluginError(plugin, method, err instanceof Error ? err : new Error(String(err)));
164
+ }
165
+ }
166
+ }
167
+ /**
168
+ * Dispatch plugin lifecycle events in a typesafe way.
169
+ * Only Plugins that expose the supplied property will be called.
170
+ *
171
+ * Can also be used to get a definite return value after passing it to plugins:
172
+ * Calls plugins sequentially and passes on a value (waterfall style).
173
+ *
174
+ * The plugins can either modify the value or return an updated one.
175
+ * Will return the latest, updated value which ran through all plugins.
176
+ *
177
+ * By convention only the first argument will be used as the updated value.
178
+ *
179
+ * @param method - The lifecycle method name
180
+ * @param args - Optional: Any arguments to be supplied to the plugin methods
181
+ * @internal
182
+ */
183
+ async dispatchBlocking(method, ...args) {
184
+ const plugins = this.filterByMethod(method);
185
+ debug('dispatchBlocking', method, {
186
+ all: this._plugins.length,
187
+ filteredByMethod: plugins.length,
188
+ });
189
+ let retValue = null;
190
+ for (const plugin of plugins) {
191
+ try {
192
+ args = this._addPuppeteerCompatIfNeeded.bind(this)(plugin, method, args);
193
+ const pluginMethod = plugin[method];
194
+ if (typeof pluginMethod === 'function') {
195
+ // @ts-expect-error - Dynamic plugin method invocation with variable args
196
+ retValue = (await pluginMethod.call(plugin, ...args));
197
+ // In case we got a return value use that as new first argument for followup function calls
198
+ if (retValue !== undefined) {
199
+ args[0] = retValue;
200
+ }
201
+ }
202
+ }
203
+ catch (err) {
204
+ this.onPluginError(plugin, method, err instanceof Error ? err : new Error(String(err)));
205
+ return retValue;
206
+ }
207
+ }
208
+ return retValue;
209
+ }
210
+ /**
211
+ * Order plugins that have expressed a special placement requirement.
212
+ *
213
+ * This is useful/necessary for e.g. plugins that depend on the data from other plugins.
214
+ *
215
+ * @private
216
+ */
217
+ order() {
218
+ debug('order:before', this.names);
219
+ const runLast = this._plugins
220
+ .filter(p => p.requirements?.has('runLast'))
221
+ .map(p => p.name);
222
+ for (const name of runLast) {
223
+ const index = this._plugins.findIndex(p => p.name === name);
224
+ if (index >= 0) {
225
+ const plugin = this._plugins.splice(index, 1)[0];
226
+ if (plugin) {
227
+ this._plugins.push(plugin);
228
+ }
229
+ }
230
+ }
231
+ debug('order:after', this.names);
232
+ }
233
+ /**
234
+ * Collects the exposed `data` property of all registered plugins.
235
+ * Will be reduced/flattened to a single array.
236
+ *
237
+ * Can be accessed by plugins that listed the `dataFromPlugins` requirement.
238
+ *
239
+ * Implemented mainly for plugins that need data from other plugins (e.g. `user-preferences`).
240
+ *
241
+ * @see [PuppeteerExtraPlugin]/data
242
+ * @param name - Filter data by optional name
243
+ *
244
+ * @private
245
+ */
246
+ getData(name) {
247
+ const data = this._plugins
248
+ .filter(p => !!p.data)
249
+ .map(p => (Array.isArray(p.data) ? p.data : [p.data]))
250
+ .reduce((acc, arr) => acc.concat(arr), []);
251
+ return name
252
+ ? data.filter((d) => typeof d === 'object' &&
253
+ d !== null &&
254
+ 'name' in d &&
255
+ d.name === name)
256
+ : data;
257
+ }
258
+ /**
259
+ * Handle `plugins` stanza (already instantiated plugins that don't require dynamic imports)
260
+ */
261
+ resolvePluginsStanza() {
262
+ debug('resolvePluginsStanza');
263
+ const pluginNames = new Set(this.names);
264
+ this._plugins
265
+ .filter(p => !!p.plugins && p.plugins.length)
266
+ .filter(p => !pluginNames.has(p.name)) // TBD: Do we want to filter out existing?
267
+ .forEach(parent => {
268
+ (parent.plugins || []).forEach(p => {
269
+ debug(parent.name, 'adding missing plugin', p.name);
270
+ this.add(p);
271
+ });
272
+ });
273
+ }
274
+ /**
275
+ * Handle `dependencies` stanza (which requires dynamic imports)
276
+ *
277
+ * Plugins can define `dependencies` as a Set or Array of dependency paths, or a Map with additional opts
278
+ *
279
+ * @note
280
+ * - The default opts for implicit dependencies can be defined using `setDependencyDefaults()`
281
+ * - Dynamic imports can be avoided by providing plugin modules with `setDependencyResolution()`
282
+ */
283
+ resolveDependenciesStanza() {
284
+ debug('resolveDependenciesStanza');
285
+ /** Attempt to dynamically require a plugin module */
286
+ const requireDependencyOrDie = (parentName, dependencyPath) => {
287
+ // If the user provided the plugin module already we use that
288
+ if (this._dependencyResolution.has(dependencyPath)) {
289
+ return this._dependencyResolution.get(dependencyPath);
290
+ }
291
+ const possiblePrefixes = ['puppeteer-extra-plugin-']; // could be extended later
292
+ const isAlreadyPrefixed = possiblePrefixes.some(prefix => dependencyPath.startsWith(prefix));
293
+ const packagePaths = [];
294
+ // If the dependency is not already prefixed we attempt to require all possible combinations to find one that works
295
+ if (!isAlreadyPrefixed) {
296
+ packagePaths.push(...possiblePrefixes.map(prefix => prefix + dependencyPath));
297
+ }
298
+ // We always attempt to require the path verbatim (as a last resort)
299
+ packagePaths.push(dependencyPath);
300
+ const pluginModule = requirePackages(packagePaths);
301
+ if (pluginModule) {
302
+ return pluginModule;
303
+ }
304
+ const explanation = `
305
+ The plugin '${parentName}' listed '${dependencyPath}' as dependency,
306
+ which could not be found. Please install it:
307
+
308
+ ${packagePaths
309
+ .map(packagePath => `npm i ${packagePath.split('/')[0]}`)
310
+ .join(`\n or:\n`)}
311
+
312
+ Note: You don't need to require the plugin yourself,
313
+ unless you want to modify it's default settings.
314
+
315
+ If your bundler has issues with dynamic imports take a look at '.plugins.setDependencyResolution()'.
316
+ `;
317
+ console.warn(explanation);
318
+ throw new Error('Plugin dependency not found');
319
+ };
320
+ const existingPluginNames = new Set(this.names);
321
+ const recursivelyLoadMissingDependencies = ({ name: parentName, dependencies, }) => {
322
+ if (!dependencies) {
323
+ return;
324
+ }
325
+ const processDependency = (dependencyPath, opts) => {
326
+ const pluginModule = requireDependencyOrDie(parentName, dependencyPath);
327
+ opts = opts || this._dependencyDefaults.get(dependencyPath) || {};
328
+ const plugin = pluginModule(opts);
329
+ if (existingPluginNames.has(plugin.name)) {
330
+ debug(parentName, '=> dependency already exists:', plugin.name);
331
+ return;
332
+ }
333
+ existingPluginNames.add(plugin.name);
334
+ debug(parentName, '=> adding new dependency:', plugin.name, opts);
335
+ this.add(plugin);
336
+ return recursivelyLoadMissingDependencies(plugin);
337
+ };
338
+ if (dependencies instanceof Set || Array.isArray(dependencies)) {
339
+ for (const dependencyPath of dependencies) {
340
+ processDependency(dependencyPath);
341
+ }
342
+ return;
343
+ }
344
+ if (dependencies instanceof Map) {
345
+ // Note: `k,v => v,k` (Map + forEach will reverse the order)
346
+ for (const [k, v] of dependencies) {
347
+ processDependency(k, v);
348
+ }
349
+ }
350
+ };
351
+ this.list.forEach(recursivelyLoadMissingDependencies);
352
+ }
353
+ /**
354
+ * Lightweight plugin dependency management to require plugins and code mods on demand.
355
+ * @private
356
+ */
357
+ resolveDependencies() {
358
+ debug('resolveDependencies');
359
+ this.resolvePluginsStanza();
360
+ this.resolveDependenciesStanza();
361
+ }
362
+ }
363
+ //# sourceMappingURL=plugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/plugins.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,KAAK,GAAG,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAEhD,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAS5E,MAAM,OAAO,UAAU;IACJ,QAAQ,GAAa,EAAE,CAAC;IACxB,mBAAmB,GAAyB,IAAI,GAAG,EAAE,CAAC;IACtD,qBAAqB,GACpC,IAAI,GAAG,EAAE,CAAC;IAEZ;;OAEG;IACH,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;;;;OAKG;IACI,GAAG,CAAC,MAAc;QACvB,IAAI,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,EAAE,CAAC;YACxC,OAAO,KAAK,CAAC;QACf,CAAC;QACD,IAAI,MAAM,CAAC,kBAAkB,EAAE,CAAC;YAC9B,MAAM,CAAC,kBAAkB,CAAC,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC,CAAC;QACzD,CAAC;QACD,oGAAoG;QACpG,IAAI,MAAM,CAAC,0BAA0B,EAAE,CAAC;YACtC,MAAM,CAAC,0BAA0B,CAAC,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,MAAM,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AAC,CAAC;IACxD,CAAC;IAED;;;OAGG;IACO,mBAAmB;QAC3B,KAAK,CAAC,qBAAqB,CAAC,CAAC;QAC7B,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,yBAAyB,EAAE,CAAC;IACnC,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ import type * as pw from 'playwright-core';
2
+ export type PlaywrightObject = pw.Page | pw.Frame | pw.Browser;
3
+ export interface PuppeteerBrowserShim {
4
+ isCompatShim?: boolean;
5
+ isPlaywright?: boolean;
6
+ pages?: pw.BrowserContext['pages'];
7
+ userAgent: () => Promise<'string'>;
8
+ }
9
+ export interface PuppeteerPageShim {
10
+ isCompatShim?: boolean;
11
+ isPlaywright?: boolean;
12
+ browser?: () => pw.Browser;
13
+ evaluateOnNewDocument?: pw.Page['addInitScript'];
14
+ _client: () => pw.CDPSession;
15
+ }
16
+ export declare const isPlaywrightPage: (obj: unknown) => obj is pw.Page;
17
+ export declare const isPlaywrightFrame: (obj: unknown) => obj is pw.Frame;
18
+ export declare const isPlaywrightBrowser: (obj: unknown) => obj is pw.Browser;
19
+ export declare const isPuppeteerCompat: (obj?: unknown) => obj is PlaywrightObject;
20
+ /** Augment a Playwright object with compatibility with certain Puppeteer methods */
21
+ export declare function addPuppeteerCompat<Input extends pw.Page | pw.Frame | pw.Browser | null>(object: Input): Input;
22
+ export declare function getPageCDPSession(page: pw.Page | pw.Frame): Promise<pw.CDPSession>;
23
+ export declare function getBrowserCDPSession(browser: pw.Browser): Promise<pw.CDPSession>;
24
+ export declare function createPageShim(page: pw.Page | pw.Frame): pw.Page | pw.Frame;
25
+ export declare function createBrowserShim(browser: pw.Browser): pw.Browser;
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/puppeteer-compatiblity-shim/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;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