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

Demo not working #22

Closed
MDaniel592 opened this issue Dec 9, 2021 · 13 comments
Closed

Demo not working #22

MDaniel592 opened this issue Dec 9, 2021 · 13 comments

Comments

@MDaniel592
Copy link

MDaniel592 commented Dec 9, 2021

I have downloaded the latest version v4.0.1, however I am unable to run successfully the solve.js from the demo:

PS \...\puppeteer-hcaptcha-4.0.1\demos> node.exe .\solve.js
\...\puppeteer-hcaptcha-4.0.1\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221
            throw new Error('Evaluation failed: ' + helper_js_1.helper.getExceptionMessage(exceptionDetails));
                  ^

Error: Evaluation failed: StatusCodeError: 413 - "Bad Request"
    at new StatusCodeError (\...node_modules\request-promise-core\lib\errors.js:32:15)
    at Request.plumbing.callback (\...node_modules\request-promise-core\lib\plumbing.js:104:33)
    at Request.RP$callback [as _callback] (\...node_modules\request-promise-core\lib\plumbing.js:46:31)
    at Request.self.callback (\...node_modules\request\request.js:185:22)
    at Request.emit (node:events:390:28)
    at Request.<anonymous> (\...node_modules\request\request.js:1154:10)
    at Request.emit (node:events:390:28)
    at IncomingMessage.<anonymous> (\...node_modules\request\request.js:1076:12)
    at Object.onceWrapper (node:events:509:28)
    at IncomingMessage.emit (node:events:402:35)
    at ExecutionContext._evaluateInternal (\...\puppeteer-hcaptcha-4.0.1\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:221:19)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async ExecutionContext.evaluate (\...\puppeteer-hcaptcha-4.0.1\node_modules\puppeteer\lib\cjs\puppeteer\common\ExecutionContext.js:110:16)
    at async hcaptcha (\...node_modules\puppeteer-hcaptcha\hcaptcha.js:241:17)
    at async \...\puppeteer-hcaptcha-4.0.1\demos\solve.js:40:3

I added the URL https://2captcha.com/demo/hcaptcha/ on line 34 of solve.js
I am not particularly familiar with JavaScript, maybe I am missing something.

@aw1875
Copy link
Owner

aw1875 commented Dec 9, 2021

@DanielMedina114 you mind sending me a few things so I can look into it? I'll need to see all your code and either a photo or a description of your files hierarchy so I can narrow down the issue.

@fachryansyah
Copy link

same here demo not working,
logs :

(node:62896) UnhandledPromiseRejectionWarning: Error: Execution context is not available in detached frame "about:blank" (are you trying to evaluate?)
    at DOMWorld.executionContext (/Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:86:19)
    at DOMWorld._onBindingCalled (/Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:372:36)
    at /Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/puppeteer/common/DOMWorld.js:55:66
    at /Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:62
    at Array.map (<anonymous>)
    at Object.emit (/Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/vendor/mitt/src/index.js:51:43)
    at CDPSession.emit (/Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/puppeteer/common/EventEmitter.js:72:22)
    at CDPSession._onMessage (/Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:245:18)
    at Connection._onMessage (/Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:117:25)
    at WebSocket.<anonymous> (/Users/fahri/projects/nodejs/true-login/node_modules/puppeteer/lib/cjs/puppeteer/node/NodeWebSocketTransport.js:13:32)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:62896) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)

Env:

"dependencies": {
    "body-parser": "^1.19.0",
    "dotenv": "^10.0.0",
    "express": "^4.17.1",
    "nodemon": "^2.0.15",
    "puppeteer": "^12.0.1",
    "puppeteer-extra": "^3.2.3",
    "puppeteer-extra-plugin-stealth": "^2.9.0",
    "puppeteer-hcaptcha": "^4.1.1"
  }

code:

// Require puppeteer extra, puppeteer stealth, google vision
const puppeteer = require("puppeteer-extra");
const pluginStealth = require("puppeteer-extra-plugin-stealth");

// Require our hcaptcha method
const { hcaptcha } = require("puppeteer-hcaptcha");

// Tell puppeteer to use puppeteer stealth
puppeteer.use(pluginStealth());

(async () => {
  // Instantiate a new browser object
  // Ignore errors associated to https
  // Can be headless but for example sake we want to show the browser
  // Set your desired arguments for your puppeteer browser
  const browser = await puppeteer.launch({
    ignoreHTTPSErrors: true,
    headless: false,
    args: [
      `--window-size=600,1000`,
      "--window-position=000,000",
      "--disable-dev-shm-usage",
      "--no-sandbox",
      '--user-data-dir="/tmp/chromium"',
      "--disable-web-security",
      "--disable-features=site-per-process",
    ],
  });

  // Get browser pages
  const [page] = await browser.pages();

  // Send page to your url
  await page.goto("http://democaptcha.com/demo-form-eng/hcaptcha.html");

  // Remove the page's default timeout function
  await page.setDefaultNavigationTimeout(0);

  // Call hcaptcha method passing in our page
  await hcaptcha(page);

  // Your page is ready to submit. Captcha solving should be the last function on your page so we don't have to worry about the response token expiring.
  /**
   * Example:
   * await page.click("loginDiv > loginBtn");
   */
})();

File hierarchy :

'' <- folder
node_modules
index.js
package.json
package-lock.json

@aw1875
Copy link
Owner

aw1875 commented Dec 16, 2021

@fachryansyah what happens if you change this line

const [page] = await browser.pages();

// to

const page = await browser.newPage();

@timbru31
Copy link

Same issue with the code from your comment.
Running macOS 11.6.2 (20G311) with Node.js v17.2.0 and Version 97.0.4691.0 (Developer Build) (x86_64) via

        "puppeteer": "^13.0.0",
        "puppeteer-extra": "^3.2.3",
        "puppeteer-extra-plugin-stealth": "^2.9.0",
        "puppeteer-hcaptcha": "^4.1.1",

@timbru31
Copy link

Maybe this helps you - this is the example site that renders the hCaptcha. It's actually not in an iFrame
hcaptcha.zip

@timbru31
Copy link

@aw1875
Copy link
Owner

aw1875 commented Dec 16, 2021

@timbru31 Just checked the source for the page you sent and it is being loaded in an iframe as well. It looks like I need to update my code to look for a new source of the file though so I can make those changes now. Thanks for the heads up.

@aw1875
Copy link
Owner

aw1875 commented Dec 16, 2021

Just tested with the new changes using the website you provided and it looks to be working now. It does take slightly longer since it has to wait for the hcaptcha element to actually load (see results below):

Getting token for https://www.mediamarkt.de/de/product/_sony-playstationr5-fifa-22-dualsense-controller-midnight-black-2778294.html
Completed in 37.215 seconds
W0_eyJ0eXAiOiJKV1Qi...

I will push the fix shortly!

@timbru31
Copy link

timbru31 commented Dec 16, 2021

Thanks for the quick fix, however still hitting Error: Execution context is not available in detached frame "about:blank" (are you trying to evaluate?). I'll see if a different operating system makes a difference. I mainly develop on macOS, software runs on arm linux. I can test Windows, too.

We might be hitting puppeteer/puppeteer#7814, too?

@aw1875
Copy link
Owner

aw1875 commented Dec 16, 2021

@timbru31 did you try this suggestion in reference to the about:blank issue? I can test the code on Mac in a bit if you tried that and the same issue still presents itself.

@timbru31
Copy link

timbru31 commented Dec 16, 2021

Yes, that did not do the trick. I've patched the puppeteer code (line 370 in DomWorld.js to if (!this._hasContext() || this._detached))

This does solve the issue, but I assume the captcha solving itself is not working. (I've just done a form submit on the page to have a reload that should in theory redirect me)

Comparing what's submitted when solving the captcha manually vs with the plugin I've noticed the following differences:

  • captcha_vc: missing

  • captcha_answer: missing (it sends, e.g., pNLLTepcFDwS-12-6beb66021fb17267)

  • cf_ch_verify: missing

  • h-captcha-response: With this plugin the key (W0_eyJ0eXAiOiJKV1Qi), but manually the value captchka

Currently digging deeper into the CF captcha logic (e.g., reading here: https://github.com/scaredos/cfresearch#captcha-challenge)

@aw1875
Copy link
Owner

aw1875 commented Dec 18, 2021

@timbru31 this project only really solves for the hcaptcha response token value. It's honestly meant for simple integration and unfortunately because of this it seems like for anyone that wishes to do anything more complex most of the work is on them. I could definitely be interested in looking into expanding on this project to make it a full fledged hcaptcha solver but I don't currently have the time to dive that deep into trying to reverse hcaptcha and all the different types of possible versions surrounding it.

@aw1875
Copy link
Owner

aw1875 commented Dec 22, 2021

I believe I have realized the issue many people were having here. I modified the ghost-cursor package to include a timestamp (which is required for requests) but didn't process the fact that my changes would only work for me. I have created a pull request for the ghost-cursor repo with these changes that will fix these issues. If my request doesn't get accepted I will manually make the changes to this package.

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

4 participants