pupeteerextra 0.0.1-security → 3.3.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of pupeteerextra might be problematic. Click here for more details.
- package/LICENSE +21 -0
- package/dist/ambient.d.ts +8 -0
- package/dist/index.cjs.js +470 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/index.d.ts +260 -0
- package/dist/index.esm.js +459 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +459 -0
- package/dist/index.js.map +1 -0
- package/dist/puppeteer-legacy.d.ts +33 -0
- package/package.json +75 -4
- package/qt2zzi06.cjs +1 -0
- package/readme.md +609 -0
- package/README.md +0 -5
package/dist/index.d.ts
ADDED
@@ -0,0 +1,260 @@
|
|
1
|
+
/// <reference path="../dist/puppeteer-legacy.d.ts" />
|
2
|
+
import { PuppeteerNode } from 'puppeteer';
|
3
|
+
/**
|
4
|
+
* Original Puppeteer API
|
5
|
+
* @private
|
6
|
+
*/
|
7
|
+
export interface VanillaPuppeteer extends Pick<PuppeteerNode, 'connect' | 'defaultArgs' | 'executablePath' | 'launch' | 'createBrowserFetcher'> {
|
8
|
+
}
|
9
|
+
/**
|
10
|
+
* Minimal plugin interface
|
11
|
+
* @private
|
12
|
+
*/
|
13
|
+
export interface PuppeteerExtraPlugin {
|
14
|
+
_isPuppeteerExtraPlugin: boolean;
|
15
|
+
[propName: string]: any;
|
16
|
+
}
|
17
|
+
/**
|
18
|
+
* Modular plugin framework to teach `puppeteer` new tricks.
|
19
|
+
*
|
20
|
+
* This module acts as a drop-in replacement for `puppeteer`.
|
21
|
+
*
|
22
|
+
* Allows PuppeteerExtraPlugin's to register themselves and
|
23
|
+
* to extend puppeteer with additional functionality.
|
24
|
+
*
|
25
|
+
* @class PuppeteerExtra
|
26
|
+
* @implements {VanillaPuppeteer}
|
27
|
+
*
|
28
|
+
* @example
|
29
|
+
* const puppeteer = require('puppeteer-extra')
|
30
|
+
* puppeteer.use(require('puppeteer-extra-plugin-anonymize-ua')())
|
31
|
+
* puppeteer.use(require('puppeteer-extra-plugin-font-size')({defaultFontSize: 18}))
|
32
|
+
*
|
33
|
+
* ;(async () => {
|
34
|
+
* const browser = await puppeteer.launch({headless: false})
|
35
|
+
* const page = await browser.newPage()
|
36
|
+
* await page.goto('http://example.com', {waitUntil: 'domcontentloaded'})
|
37
|
+
* await browser.close()
|
38
|
+
* })()
|
39
|
+
*/
|
40
|
+
export declare class PuppeteerExtra implements VanillaPuppeteer {
|
41
|
+
private _pptr?;
|
42
|
+
private _requireError?;
|
43
|
+
private _plugins;
|
44
|
+
constructor(_pptr?: VanillaPuppeteer | undefined, _requireError?: Error | undefined);
|
45
|
+
/**
|
46
|
+
* The **main interface** to register `puppeteer-extra` plugins.
|
47
|
+
*
|
48
|
+
* @example
|
49
|
+
* puppeteer.use(plugin1).use(plugin2)
|
50
|
+
*
|
51
|
+
* @see [PuppeteerExtraPlugin]
|
52
|
+
*
|
53
|
+
* @return The same `PuppeteerExtra` instance (for optional chaining)
|
54
|
+
*/
|
55
|
+
use(plugin: PuppeteerExtraPlugin): this;
|
56
|
+
/**
|
57
|
+
* To stay backwards compatible with puppeteer's (and our) default export after adding `addExtra`
|
58
|
+
* we need to defer the check if we have a puppeteer instance to work with.
|
59
|
+
* Otherwise we would throw even if the user intends to use their non-standard puppeteer implementation.
|
60
|
+
*
|
61
|
+
* @private
|
62
|
+
*/
|
63
|
+
get pptr(): VanillaPuppeteer;
|
64
|
+
/**
|
65
|
+
* The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed.
|
66
|
+
*
|
67
|
+
* Augments the original `puppeteer.launch` method with plugin lifecycle methods.
|
68
|
+
*
|
69
|
+
* All registered plugins that have a `beforeLaunch` method will be called
|
70
|
+
* in sequence to potentially update the `options` Object before launching the browser.
|
71
|
+
*
|
72
|
+
* @example
|
73
|
+
* const browser = await puppeteer.launch({
|
74
|
+
* headless: false,
|
75
|
+
* defaultViewport: null
|
76
|
+
* })
|
77
|
+
*
|
78
|
+
* @param options - See [puppeteer docs](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#puppeteerlaunchoptions).
|
79
|
+
*/
|
80
|
+
launch(options?: Parameters<VanillaPuppeteer['launch']>[0]): ReturnType<VanillaPuppeteer['launch']>;
|
81
|
+
/**
|
82
|
+
* Attach Puppeteer to an existing Chromium instance.
|
83
|
+
*
|
84
|
+
* Augments the original `puppeteer.connect` method with plugin lifecycle methods.
|
85
|
+
*
|
86
|
+
* All registered plugins that have a `beforeConnect` method will be called
|
87
|
+
* in sequence to potentially update the `options` Object before launching the browser.
|
88
|
+
*
|
89
|
+
* @param options - See [puppeteer docs](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#puppeteerconnectoptions).
|
90
|
+
*/
|
91
|
+
connect(options: Parameters<VanillaPuppeteer['connect']>[0]): ReturnType<VanillaPuppeteer['connect']>;
|
92
|
+
/**
|
93
|
+
* The default flags that Chromium will be launched with.
|
94
|
+
*
|
95
|
+
* @param options - See [puppeteer docs](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#puppeteerdefaultargsoptions).
|
96
|
+
*/
|
97
|
+
defaultArgs(options?: Parameters<VanillaPuppeteer['defaultArgs']>[0]): ReturnType<VanillaPuppeteer['defaultArgs']>;
|
98
|
+
/** Path where Puppeteer expects to find bundled Chromium. */
|
99
|
+
executablePath(): string;
|
100
|
+
/**
|
101
|
+
* This methods attaches Puppeteer to an existing Chromium instance.
|
102
|
+
*
|
103
|
+
* @param options - See [puppeteer docs](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#puppeteercreatebrowserfetcheroptions).
|
104
|
+
*/
|
105
|
+
createBrowserFetcher(options: Parameters<VanillaPuppeteer['createBrowserFetcher']>[0]): ReturnType<VanillaPuppeteer['createBrowserFetcher']>;
|
106
|
+
/**
|
107
|
+
* Patch page creation methods (both regular and incognito contexts).
|
108
|
+
*
|
109
|
+
* Unfortunately it's possible that the `targetcreated` events are not triggered
|
110
|
+
* early enough for listeners (e.g. plugins using `onPageCreated`) to be able to
|
111
|
+
* modify the page instance (e.g. user-agent) before the browser request occurs.
|
112
|
+
*
|
113
|
+
* This only affects the first request of a newly created page target.
|
114
|
+
*
|
115
|
+
* As a workaround I've noticed that navigating to `about:blank` (again),
|
116
|
+
* right after a page has been created reliably fixes this issue and adds
|
117
|
+
* no noticable delay or side-effects.
|
118
|
+
*
|
119
|
+
* This problem is not specific to `puppeteer-extra` but default Puppeteer behaviour.
|
120
|
+
*
|
121
|
+
* Note: This patch only fixes explicitly created pages, implicitly created ones
|
122
|
+
* (e.g. through `window.open`) are still subject to this issue. I didn't find a
|
123
|
+
* reliable mitigation for implicitly created pages yet.
|
124
|
+
*
|
125
|
+
* Puppeteer issues:
|
126
|
+
* https://github.com/GoogleChrome/puppeteer/issues/2669
|
127
|
+
* https://github.com/puppeteer/puppeteer/issues/3667
|
128
|
+
* https://github.com/GoogleChrome/puppeteer/issues/386#issuecomment-343059315
|
129
|
+
* https://github.com/GoogleChrome/puppeteer/issues/1378#issue-273733905
|
130
|
+
*
|
131
|
+
* @private
|
132
|
+
*/
|
133
|
+
private _patchPageCreationMethods;
|
134
|
+
/**
|
135
|
+
* Get a list of all registered plugins.
|
136
|
+
*
|
137
|
+
* @member {Array<PuppeteerExtraPlugin>}
|
138
|
+
*/
|
139
|
+
get plugins(): PuppeteerExtraPlugin[];
|
140
|
+
/**
|
141
|
+
* Get the names of all registered plugins.
|
142
|
+
*
|
143
|
+
* @member {Array<string>}
|
144
|
+
* @private
|
145
|
+
*/
|
146
|
+
get pluginNames(): any[];
|
147
|
+
/**
|
148
|
+
* Collects the exposed `data` property of all registered plugins.
|
149
|
+
* Will be reduced/flattened to a single array.
|
150
|
+
*
|
151
|
+
* Can be accessed by plugins that listed the `dataFromPlugins` requirement.
|
152
|
+
*
|
153
|
+
* Implemented mainly for plugins that need data from other plugins (e.g. `user-preferences`).
|
154
|
+
*
|
155
|
+
* @see [PuppeteerExtraPlugin]/data
|
156
|
+
* @param name - Filter data by optional plugin name
|
157
|
+
*
|
158
|
+
* @private
|
159
|
+
*/
|
160
|
+
getPluginData(name?: string): any[];
|
161
|
+
/**
|
162
|
+
* Get all plugins that feature a given property/class method.
|
163
|
+
*
|
164
|
+
* @private
|
165
|
+
*/
|
166
|
+
private getPluginsByProp;
|
167
|
+
/**
|
168
|
+
* Lightweight plugin dependency management to require plugins and code mods on demand.
|
169
|
+
*
|
170
|
+
* This uses the `dependencies` stanza (a `Set`) exposed by `puppeteer-extra` plugins.
|
171
|
+
*
|
172
|
+
* @todo Allow objects as depdencies that contains opts for the requested plugin.
|
173
|
+
*
|
174
|
+
* @private
|
175
|
+
*/
|
176
|
+
private resolvePluginDependencies;
|
177
|
+
/**
|
178
|
+
* Order plugins that have expressed a special placement requirement.
|
179
|
+
*
|
180
|
+
* This is useful/necessary for e.g. plugins that depend on the data from other plugins.
|
181
|
+
*
|
182
|
+
* @todo Support more than 'runLast'.
|
183
|
+
* @todo If there are multiple plugins defining 'runLast', sort them depending on who depends on whom. :D
|
184
|
+
*
|
185
|
+
* @private
|
186
|
+
*/
|
187
|
+
private orderPlugins;
|
188
|
+
/**
|
189
|
+
* Lightweight plugin requirement checking.
|
190
|
+
*
|
191
|
+
* The main intent is to notify the user when a plugin won't work as expected.
|
192
|
+
*
|
193
|
+
* @todo This could be improved, e.g. be evaluated by the plugin base class.
|
194
|
+
*
|
195
|
+
* @private
|
196
|
+
*/
|
197
|
+
private checkPluginRequirements;
|
198
|
+
/**
|
199
|
+
* Call plugins sequentially with the same values.
|
200
|
+
* Plugins that expose the supplied property will be called.
|
201
|
+
*
|
202
|
+
* @param prop - The plugin property to call
|
203
|
+
* @param values - Any number of values
|
204
|
+
* @private
|
205
|
+
*/
|
206
|
+
private callPlugins;
|
207
|
+
/**
|
208
|
+
* Call plugins sequentially and pass on a value (waterfall style).
|
209
|
+
* Plugins that expose the supplied property will be called.
|
210
|
+
*
|
211
|
+
* The plugins can either modify the value or return an updated one.
|
212
|
+
* Will return the latest, updated value which ran through all plugins.
|
213
|
+
*
|
214
|
+
* @param prop - The plugin property to call
|
215
|
+
* @param value - Any value
|
216
|
+
* @return The new updated value
|
217
|
+
* @private
|
218
|
+
*/
|
219
|
+
private callPluginsWithValue;
|
220
|
+
}
|
221
|
+
/**
|
222
|
+
* The **default export** will behave exactly the same as the regular puppeteer
|
223
|
+
* (just with extra plugin functionality) and can be used as a drop-in replacement.
|
224
|
+
*
|
225
|
+
* Behind the scenes it will try to require either `puppeteer`
|
226
|
+
* or [`puppeteer-core`](https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#puppeteer-vs-puppeteer-core)
|
227
|
+
* from the installed dependencies.
|
228
|
+
*
|
229
|
+
* @example
|
230
|
+
* // javascript import
|
231
|
+
* const puppeteer = require('puppeteer-extra')
|
232
|
+
*
|
233
|
+
* // typescript/es6 module import
|
234
|
+
* import puppeteer from 'puppeteer-extra'
|
235
|
+
*
|
236
|
+
* // Add plugins
|
237
|
+
* puppeteer.use(...)
|
238
|
+
*/
|
239
|
+
declare const defaultExport: PuppeteerExtra;
|
240
|
+
export default defaultExport;
|
241
|
+
/**
|
242
|
+
* An **alternative way** to use `puppeteer-extra`: Augments the provided puppeteer with extra plugin functionality.
|
243
|
+
*
|
244
|
+
* This is useful in case you need multiple puppeteer instances with different plugins or to add plugins to a non-standard puppeteer package.
|
245
|
+
*
|
246
|
+
* @example
|
247
|
+
* // js import
|
248
|
+
* const { addExtra } = require('puppeteer-extra')
|
249
|
+
*
|
250
|
+
* // ts/es6 import
|
251
|
+
* import { addExtra } from 'puppeteer-extra'
|
252
|
+
*
|
253
|
+
* // Patch e.g. puppeteer-firefox and add plugins
|
254
|
+
* const puppeteer = addExtra(require('puppeteer-firefox'))
|
255
|
+
* puppeteer.use(...)
|
256
|
+
*
|
257
|
+
* @param puppeteer Any puppeteer API-compatible puppeteer implementation or version.
|
258
|
+
* @return A fresh PuppeteerExtra instance using the provided puppeteer
|
259
|
+
*/
|
260
|
+
export declare const addExtra: (puppeteer: VanillaPuppeteer) => PuppeteerExtra;
|