Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

Node.JS Loop and handling errors Puppeteer

Nuven

New Coder
Hi there!

I am looking for a solution to automate my script to re-run in an infinite loop till the script is stopped, and also i am having difficulties to let the script continue after any error, it should just re-start the process.

At current, if all goes well it will run for some time till i get and error, then requires me to re-run the script manually evetime, here is the error i receive:

Code:
? new Error(`${response.errorText} at ${url}`)
                      ^

Error: net::ERR_CONNECTION_CLOSED at https://*********.com
    at navigate (file:///C:/Users/Omega/Desktop/GOLOGIN/node_modules/puppeteer-core/lib/esm/puppeteer/common/Frame.js:210:23)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Frame.goto (file:///C:/Users/Omega/Desktop/GOLOGIN/node_modules/puppeteer-core/lib/esm/puppeteer/common/Frame.js:180:21)
    at async CDPPage.goto (file:///C:/Users/Omega/Desktop/GOLOGIN/node_modules/puppeteer-core/lib/esm/puppeteer/common/Page.js:436:16)
    at async file:///C:/Users/Omega/Desktop/GOLOGIN/create.js:65:3

Here is my full code:

Code:
import puppeteer from 'puppeteer-core';

import GoLogin from './node_modules/gologin/src/gologin.js';

const delay = ms => new Promise(res => setTimeout(res, ms));

const { connect } = puppeteer;

function fingerprint(){

(async () => {
  const GL = new GoLogin({
    token: '********************',
  });

  // Generate Random Profile Username
  let randomProfile = Math.floor(Math.random()*89999+1000000)

  // next parameters are required for creating

  const profile_id = await GL.create({
    name: randomProfile,
    os: 'win',
    navigator: {
      language: 'enUS',
      userAgent: 'random', // get random user agent for selected os
      resolution: '1920x1080',
      platform: 'win',
    },
    proxyEnabled: true,
     proxy: {
        mode:   'http',
        host:   '********.com',
        port:   '10000',
        username:   '*******',
        password:   '*******',
        autoProxyRegion: 'us',
     },
  });

  console.log('profile id=', profile_id);



  await GL.update({
    id: profile_id,
    name: randomProfile,
  });

  const profile = await GL.getProfile(profile_id);

  console.log('new profile name=', profile.name);

  // Goto site and wait, then delete profile
  const { status, wsUrl } = await GL.start();
  const browser = await connect({
    browserWSEndpoint: wsUrl.toString(),
    ignoreHTTPSErrors: true,
  });



  const page = await browser.newPage();
  await page.goto('https://*************.com');
  await delay(5000);
  console.log(await page.content());
  await delay(15000);
  await browser.close();
  await GL.stopLocal({ posting: false });
  await GL.delete(profile_id);
  console.log('Success');
  //await GL.delete(profile_id);


})();

};

function run() {
    setInterval(fingerprint, 25000);
  };
 
  run();

Any advice will be highly appreciated!
 
I've no idea what this code does or what it's connecting to, but it seems to me the web server has closed the connection. Perhaps there were to many requests in too short a time ? Not sure if Node.js has network monitoring like a browser has, it might be useful to see if there are any HTTP status codes.
 
I've no idea what this code does or what it's connecting to, but it seems to me the web server has closed the connection. Perhaps there were to many requests in too short a time ? Not sure if Node.js has network monitoring like a browser has, it might be useful to see if there are any HTTP status codes.

Hi,

The code connects to gologin to create an unique browser, then proceeding to a certain site, idle a few seconds and close the connection and then delete the created gologin profile from the account.

The issue i am experiencing is as described above regards the error, the script loops, but once that error comes up (most likely that the system cannot see the specified site, then gives the error as indicated).

I am no pro in js script coding, all above ive managed to put together with details from gologin api documentation. So i am looking for a way that "catches" the error code, but not stop the script, rather do a "retry" or "restart" the script so it can run 24/7 without myself to monitor the when running due to that specific error.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom