* The **main interface** to register `puppeteer-extra` plugins. * * @example * puppeteer.use(plugin1).use(plugin2) * * @see [PuppeteerExtraPlugin] * * @return The same `PuppeteerExtra` instance (for optional chaining)
(plugin: PuppeteerExtraPlugin)
| 79 | * @return The same `PuppeteerExtra` instance (for optional chaining) |
| 80 | */ |
| 81 | use(plugin: PuppeteerExtraPlugin): this { |
| 82 | if (typeof plugin !== 'object' || !plugin._isPuppeteerExtraPlugin) { |
| 83 | console.error( |
| 84 | `Warning: Plugin is not derived from PuppeteerExtraPlugin, ignoring.`, |
| 85 | plugin |
| 86 | ) |
| 87 | return this |
| 88 | } |
| 89 | if (!plugin.name) { |
| 90 | console.error( |
| 91 | `Warning: Plugin with no name registering, ignoring.`, |
| 92 | plugin |
| 93 | ) |
| 94 | return this |
| 95 | } |
| 96 | if (plugin.requirements.has('dataFromPlugins')) { |
| 97 | plugin.getDataFromPlugins = this.getPluginData.bind(this) |
| 98 | } |
| 99 | plugin._register(Object.getPrototypeOf(plugin)) |
| 100 | this._plugins.push(plugin) |
| 101 | debug('plugin registered', plugin.name) |
| 102 | return this |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * To stay backwards compatible with puppeteer's (and our) default export after adding `addExtra` |