HTTP server conflicting with Puppeteer after the first use

I’m trying to make a server using HTTP library where a page is loaded using Puppeteer, but it seems to work only once before returning “Hmm… We couldn’t reach your Repl”. I saw this problem with other people, so I’m looking for a solution but seems is a bug instead. Apologies if this is not the correct category.

Source code:

const http = require('http');
const puppeteer = require('puppeteer');
const waitUntil = require('async-wait-until').waitUntil;

var running = false;
const server = http.createServer((request, response) => {
  console.log(request.url);
  if (request.url == '/start') {
    if (running) {
      new Promise(resolve => setTimeout(resolve, 1500)).then(() => { response.end(); });
    } else {
      running = true;
      (async() => {
        const browser = await puppeteer.launch({ headless: false, args: ['--no-sandbox', '--disable-setuid-sandbox'] });
        const page = await browser.newPage();
        page.goto('https://replit.com');
        
        await waitUntil(() => !running, { timeout : Infinity });
        await browser.close();
      })().then(() => { running = false; response.end(); } )
    };
  } else if (request.url == '/stop') {
      running = false;
      response.end();
  } else {
      response.end('404');
  };
});
server.listen(5000)
1 Like

Try this:

  1. Go to Shell
  2. Type: “busybox reboot”

Without the “”.

4 Likes

Thank you so much! It worked.

2 Likes

np. Have a nice day :slight_smile:

1 Like

Hi, I have the same problem.

But if I do busybox reboot, that reboot all my server. So this simply restarts the machine, so it doesn’t really solve the problem, after the first opening of puppeteer, the http server no longer receives requests.