Skip to content

Commit

Permalink
Setup tasks to run in parellel to speed up the image detection process
Browse files Browse the repository at this point in the history
  • Loading branch information
aw1875 committed Dec 14, 2021
1 parent 56e8524 commit 54c8451
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A library to solve hcaptcha challenges that are automated within puppeteer. You can automatically set response values where they should be so the only thing left for you is submitting the page or you can get the response token. Average response time is rougly 20 - 40 seconds with TensorFlow's Image Recognition.

<img src="images/newdemo.gif" height="500px"/>
<img src="images/demo.gif" height="400px"/>

### If you like this project feel free to donate!

Expand Down Expand Up @@ -107,20 +107,26 @@ const { hcaptchaToken } = require('puppeteer-hcaptcha');

## Changelog

### 4.0.1 (December 13, 2021)
### 4.0.2 (December 14, 2021)
- Setup TensorFlow tasks to run in parallel using `Promise.All` which seems to have drastically improved speeds solving [#23](https://github.com/aw1875/puppeteer-hcaptcha/issues/23)
- Test results seem to mostly be between the 13 - 16 second range (with a few outliers between 19 - 20)
- Will continue looking into ways to get back to the old speeds from using Google Cloud Vision
- Looking into the potential of using C++ or C# as a backend for true threading with the help of [edge-js](https://github.com/agracio/edge-js) or something similar

### 4.0.1 (December 8, 2021)
- Fixed issue where `useragents.json` file couldn't be found

### 4.0.0 (December 13, 2021)
### 4.0.0 (December 8, 2021)
- Removed Google Cloud Vision from dependencies
- Integrated TensorFlow Image Recognition instead
- Created fix for checking answer requests failing
- Cleaned up functions
- Documented all functions within code

### 3.0.6 (December 12, 2021)
### 3.0.6 (December 7, 2021)
- Removed setting the `g-recaptcha-response` as hCaptcha no longer requires this

### 3.0.5 (December 12, 2021)
### 3.0.5 (December 7, 2021)
- Added functions to dynamically get HSW/HSL version for getting tasklist
- Updated headers to properly request for tokens

Expand Down
30 changes: 20 additions & 10 deletions hcaptcha.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,30 @@ const getHSW = async (req) => {
* @param {*} tasks
* @returns answers map
*/
const getAnswersTF = async (request_image, tasks) => {
const getAnswersTF = async (request_image, tasks) => {
let answers = new Map();
for (const task of tasks) {
await tensor(task.datapoint_uri).then((res) => {
let [data] = res;

if (data !== undefined && data.class.toUpperCase() === request_image.toUpperCase() && data.score > 0.5) {
answers[task.task_key] = "true";
} else {
answers[task.task_key] = "false";
}
});
const threads = [];
for (const task of tasks) {
threads.push(tensor(task.datapoint_uri));
}

try {
await Promise.all(asyncCalls).then((results) => {
results.forEach((res, index) => {

let [data] = res;

if (data !== undefined && data.class.toUpperCase() === request_image.toUpperCase() && data.score > 0.5) {
answers[tasks[index].task_key] = "true";
} else {
answers[tasks[index].task_key] = "false";
}
})
})
} catch (err) {
console.log(err);
}
return answers
}

Expand Down
Binary file modified images/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed images/newdemo.gif
Binary file not shown.

0 comments on commit 54c8451

Please sign in to comment.