skip to Main Content

I’ve recently started learning JS and the answer to my question will probably be pretty easy 🙂

I need to:

  1. Get a "challenge" for a funcaptcha on the first computer
  2. Save the challenge to a text document
  3. Transfer the text document to another computer (manually)
  4. Apply getImage() to the challenge (from the first computer) to get a picture for that challenge, on the second computer.

Here is the code for step 1 and 2. It works ok.

const fun = require("funcaptcha");
const fs = require('fs');

const token = await fun.getToken({
    pkey: "476068BF-9607-4799-B53D-966BE98E2B81", // The public key
    site: "https://roblox-api.arkoselabs.com", // The site which contains the funcaptcha
}).then(async token => {
    let session = new fun.Session(token);
    let challenge = await session.getChallenge();

    image = challenge.getImage() //Just to ensure it's working okay. 

    filePath = //Path to the text file
    fs.writeFile(filePath, challenge)

});

Now, I transfer the text file to another computer and try using the following code:

const fun = require("funcaptcha");
const fs = require('fs');

const filePath = //path to file;

fs.readFile(filePath, 'utf8', (err, data) => {
  if (err) {
    console.error('Error:', err);
  } else {
    const challenge = data;
    console.log('Success:', challenge);
  }
});

image = await challenge.getImage()

This code causes the error

TypeError: challenge.getImage is not a function

Why can’t getImage() be applied to a challenge anymore? It worked great in my first code snippet.

How can this be fixed?

Thanks 🙂

P.S here is an example of "challenge" – https://pastebin.com/J9nGE1cX

Link to "funcaptcha" npm – https://www.npmjs.com/package/funcaptcha

2

Answers


  1. The error you’re encountering, TypeError: challenge.getImage is not a function, is because challenge on the second computer is just a string (the file’s content), not an object with a getImage method.

    You need to create a new Session object on the second computer, and then get a new challenge object from that session.

    const fun = require("funcaptcha");
    const fs = require('fs');
    
    const filePath = //path to file;
    
    fs.readFile(filePath, 'utf8', async (err, data) => {
      if (err) {
        console.error('Error:', err);
      } else {
        const token = data;
        console.log('Success:', token);
        let session = new fun.Session(token);
        let challenge = await session.getChallenge();
        const image = await challenge.getImage();
      }
    });
    
    Login or Signup to reply.
  2. The issue you’re facing is due to a scoping problem. In your first code snippet, the challenge variable is declared within the then callback function, making it accessible within that function. However, in the second code snippet, challenge is declared within the fs.readFile callback function, making it inaccessible outside of that function.

    To fix this, you need to ensure that the challenge variable is accessible in the scope where you want to use it. You can declare it in a higher scope, such as at the beginning of your script, so that it can be accessed both within and outside the fs.readFile callback. Here’s a modified version of your second code snippet to illustrate this:

    const fun = require("funcaptcha");
    const fs = require('fs');
    
    const filePath = // path to file;
    let challenge; // Declare challenge in a higher scope
    
    fs.readFile(filePath, 'utf8', async (err, data) => {
      if (err) {
        console.error('Error:', err);
      } else {
        challenge = data; // Assign the value of challenge from the file
        console.log('Success:', challenge);
    
        // Now you can use challenge outside this callback
        const image = await challenge.getImage();
        // Use the 'image' variable as needed
      }
    });
    

    By declaring challenge at a higher scope, you can assign its value inside the fs.readFile callback and then use it elsewhere in your script.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search