Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: callback for progress bar #30

Open
NabiKAZ opened this issue Apr 24, 2022 · 2 comments
Open

Feature: callback for progress bar #30

NabiKAZ opened this issue Apr 24, 2022 · 2 comments

Comments

@NabiKAZ
Copy link
Contributor

NabiKAZ commented Apr 24, 2022

It would be nice to send a callback to run it while waiting for the captcha to return. To notice the progress of the operation.

@NabiKAZ NabiKAZ changed the title callback for progress bar Feature: callback for progress bar Apr 24, 2022
@Furry
Copy link
Owner

Furry commented Apr 24, 2022

Could you give an example of what you mean by this? In pseudocode or something similar, having trouble picturing it.

@NabiKAZ
Copy link
Contributor Author

NabiKAZ commented Apr 25, 2022

In normal mode, see the output, the user is waiting and sees no anything in output, so it does not know if the operation is in progress or if the application is frozen!
If it was done quickly, maybe it would not be a problem. But this operation may take up to 1 minute to get the reCaptcha.

cmd_B6oHG4vLgc.mp4

But I changed the code like this:
A function can now be sent as a callback so that something can be displayed in the output while receiving captcha results.

(async function() {
const Captcha = require("2captcha");

// Callback for show progress bar
const progressBarCallback = function() {
	process.stdout.write(".");
};

// A new 'solver' instance with our API key
const solver = new Captcha.Solver("...", 1000, true, progressBarCallback);

// Example ReCaptcha Website
console.log('Getting captcha...');
await solver.recaptcha("6Ld2sf4SAAAAAKSgzs0Q13IZhY02Pyo31S2jgOB5", "https://patrickhlauke.github.io/recaptcha/")
.then((res) => {
    console.log('res:', res);
})
.catch((err) => {
	console.error('err:', err);
});

console.log('Finish.');

})();

See result:

cmd_wjkCy77mkl.mp4

I will try to send it in the form of PR.

In a more advanced way, these projects can be used to show the progress bar:
https://github.com/npkgz/cli-progress
https://github.com/visionmedia/node-progress

Or define it as an event instead of a callback function. For example:

solver.on('progress', function() {
    process.stdout.write('.');
});

NabiKAZ added a commit to NabiKAZ/2captcha that referenced this issue Apr 25, 2022
Signed-off-by: Nabi <nabikaz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants