puppeteer-extra-plugin-recaptcha
Advanced tools
Comparing version 3.1.4 to 3.1.5
/*! | ||
* puppeteer-extra-plugin-recaptcha v3.1.3 by berstend | ||
* puppeteer-extra-plugin-recaptcha v3.1.4 by berstend | ||
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha | ||
@@ -514,3 +514,3 @@ * @license MIT | ||
async onPageCreated(page) { | ||
this.debug('onPageCreated'); | ||
this.debug('onPageCreated', page.url()); | ||
// Make sure we can run our content script | ||
@@ -524,2 +524,13 @@ await page.setBypassCSP(true); | ||
page.solveRecaptchas = async () => this.solveRecaptchas(page); | ||
// Add custom methods to potential frames as well | ||
page.on('frameattached', frame => { | ||
if (!frame) | ||
return; | ||
this.debug('add methods to frame', frame.url()); | ||
frame.findRecaptchas = async () => this.findRecaptchas(frame); | ||
frame.getRecaptchaSolutions = async (captchas, provider) => this.getRecaptchaSolutions(captchas, provider); | ||
frame.enterRecaptchaSolutions = async (solutions) => this.enterRecaptchaSolutions(frame, solutions); | ||
// Add convenience methods that wraps all others | ||
frame.solveRecaptchas = async () => this.solveRecaptchas(frame); | ||
}); | ||
} | ||
@@ -526,0 +537,0 @@ } |
import { PuppeteerExtraPlugin } from 'puppeteer-extra-plugin'; | ||
import { Page } from 'puppeteer'; | ||
import { Frame, Page } from 'puppeteer'; | ||
import * as types from './types'; | ||
@@ -15,6 +15,6 @@ export declare const BuiltinSolutionProviders: types.SolutionProvider[]; | ||
private _generateContentScript; | ||
findRecaptchas(page: Page): Promise<types.FindRecaptchasResult>; | ||
findRecaptchas(page: Page | Frame): Promise<types.FindRecaptchasResult>; | ||
getRecaptchaSolutions(captchas: types.CaptchaInfo[], provider?: types.SolutionProvider): Promise<types.GetSolutionsResult>; | ||
enterRecaptchaSolutions(page: Page, solutions: types.CaptchaSolution[]): Promise<types.EnterRecaptchaSolutionsResult>; | ||
solveRecaptchas(page: Page): Promise<types.SolveRecaptchasResult>; | ||
enterRecaptchaSolutions(page: Page | Frame, solutions: types.CaptchaSolution[]): Promise<types.EnterRecaptchaSolutionsResult>; | ||
solveRecaptchas(page: Page | Frame): Promise<types.SolveRecaptchasResult>; | ||
onPageCreated(page: Page): Promise<void>; | ||
@@ -21,0 +21,0 @@ } |
/*! | ||
* puppeteer-extra-plugin-recaptcha v3.1.3 by berstend | ||
* puppeteer-extra-plugin-recaptcha v3.1.4 by berstend | ||
* https://github.com/berstend/puppeteer-extra/tree/master/packages/puppeteer-extra-plugin-recaptcha | ||
@@ -508,3 +508,3 @@ * @license MIT | ||
async onPageCreated(page) { | ||
this.debug('onPageCreated'); | ||
this.debug('onPageCreated', page.url()); | ||
// Make sure we can run our content script | ||
@@ -518,2 +518,13 @@ await page.setBypassCSP(true); | ||
page.solveRecaptchas = async () => this.solveRecaptchas(page); | ||
// Add custom methods to potential frames as well | ||
page.on('frameattached', frame => { | ||
if (!frame) | ||
return; | ||
this.debug('add methods to frame', frame.url()); | ||
frame.findRecaptchas = async () => this.findRecaptchas(frame); | ||
frame.getRecaptchaSolutions = async (captchas, provider) => this.getRecaptchaSolutions(captchas, provider); | ||
frame.enterRecaptchaSolutions = async (solutions) => this.enterRecaptchaSolutions(frame, solutions); | ||
// Add convenience methods that wraps all others | ||
frame.solveRecaptchas = async () => this.solveRecaptchas(frame); | ||
}); | ||
} | ||
@@ -520,0 +531,0 @@ } |
@@ -151,3 +151,3 @@ "use strict"; | ||
async onPageCreated(page) { | ||
this.debug('onPageCreated'); | ||
this.debug('onPageCreated', page.url()); | ||
// Make sure we can run our content script | ||
@@ -161,2 +161,13 @@ await page.setBypassCSP(true); | ||
page.solveRecaptchas = async () => this.solveRecaptchas(page); | ||
// Add custom methods to potential frames as well | ||
page.on('frameattached', frame => { | ||
if (!frame) | ||
return; | ||
this.debug('add methods to frame', frame.url()); | ||
frame.findRecaptchas = async () => this.findRecaptchas(frame); | ||
frame.getRecaptchaSolutions = async (captchas, provider) => this.getRecaptchaSolutions(captchas, provider); | ||
frame.enterRecaptchaSolutions = async (solutions) => this.enterRecaptchaSolutions(frame, solutions); | ||
// Add convenience methods that wraps all others | ||
frame.solveRecaptchas = async () => this.solveRecaptchas(frame); | ||
}); | ||
} | ||
@@ -163,0 +174,0 @@ } |
@@ -13,2 +13,3 @@ // Extend Puppeteer interfaces transparently to the end user. | ||
interface Page extends RecaptchaPluginPageAdditions {} | ||
interface Frame extends RecaptchaPluginPageAdditions {} | ||
} | ||
@@ -18,2 +19,3 @@ | ||
interface Page extends RecaptchaPluginPageAdditions {} | ||
interface Frame extends RecaptchaPluginPageAdditions {} | ||
} |
{ | ||
"name": "puppeteer-extra-plugin-recaptcha", | ||
"version": "3.1.4", | ||
"version": "3.1.5", | ||
"description": "A puppeteer-extra plugin to solve reCAPTCHAs automatically.", | ||
@@ -73,3 +73,3 @@ "main": "dist/index.cjs.js", | ||
}, | ||
"gitHead": "c9970364e39cc68d2735bf25abd23169fb16a3ed" | ||
"gitHead": "3287eb9fe6bbe0ad54c43ab78559d9bf37115109" | ||
} |
@@ -26,5 +26,15 @@ # puppeteer-extra-plugin-recaptcha [![Build Status](https://travis-ci.org/berstend/puppeteer-extra.svg?branch=master)](https://travis-ci.org/berstend/puppeteer-extra) [![npm](https://img.shields.io/npm/v/puppeteer-extra-plugin-recaptcha.svg)](https://www.npmjs.com/package/puppeteer-extra-plugin-recaptcha) | ||
#### `3.1.5` | ||
- Solving reCAPTCHAs in frames is now supported as well, if need be: | ||
```js | ||
for (const frame of page.mainFrame().childFrames()) { | ||
await frame.solveRecaptchas() | ||
} | ||
``` | ||
#### `3.1.4` | ||
- Improved TypeScript experience: I found a way to make your TypeScript compiler automaticallly aware of the additions to the `Page` object (e.g. `page.solveRecaptchas()`). | ||
- Improved TypeScript experience: I found a way to make your TypeScript compiler automatically aware of the additions to the `Page` and `Frame` object (e.g. `page.solveRecaptchas()`). | ||
- We now print a warning if the provider throws an error (e.g. invalid api key) | ||
@@ -78,2 +88,5 @@ | ||
```ts | ||
// `puppeteer-extra` and the recaptcha plugin are written in TS, | ||
// hence you get perfect type support out of the box :) | ||
import puppeteer from 'puppeteer-extra' | ||
@@ -96,3 +109,3 @@ import RecaptchaPlugin from 'puppeteer-extra-plugin-recaptcha' | ||
// Even this page mod is fully type safe 🎉 | ||
// Even this `Puppeteer.Page` extension is recognized and fully type safe 🎉 | ||
await page.solveRecaptchas() | ||
@@ -109,6 +122,4 @@ | ||
</details> | ||
</details><br> | ||
<br> | ||
If you'd like to see debug output just run your script like so: | ||
@@ -209,5 +220,17 @@ | ||
### Solving captchas in iframes | ||
By default the plugin will only solve reCAPTCHAs showing up on the immediate page. In case you encounter captchas in frames the plugin extends the `Puppeteer.Frame` object with custom methods as well (since `v3.1.5`): | ||
```js | ||
// Loop over all potential frames on that page | ||
for (const frame of page.mainFrame().childFrames()) { | ||
// Attempt to solve any potential reCAPTCHAs in those frames | ||
await frame.solveRecaptchas() | ||
} | ||
``` | ||
## API | ||
I'm currently reimplementing autogenerated API docs using typedoc (instead of jsdoc/documentation.js). Docs will be updated soon. | ||
I'm currently reimplementing autogenerated API docs using typedoc (instead of jsdoc/documentation.js). Docs will be updated soon. :) | ||
@@ -214,0 +237,0 @@ ## Todo |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
172913
1809
235