Is it possible to send a GET request to a puppeteer script?

javascript

Yes, it is possible to send a GET request to a Puppeteer script using an HTTP client library such as axios, fetch, or request. The Puppeteer script can be set up to listen for incoming HTTP requests using a web framework like Express.

For example, here’s some sample code that sets up an Express server in a Puppeteer script to listen for GET requests:

const express = require('express');
const app = express();

app.get('/', async (req, res) => {
  // Perform some actions in Puppeteer here
  // ...

  res.send('Success!');
});

const port = 3000;
app.listen(port, () => {
  console.log(`Puppeteer script listening at http://localhost:${port}`);
});

This code sets up an Express server that listens for GET requests on port 3000. When a GET request is received, the server sends a response with the string ‘Success!‘. You can modify the code to perform some actions in Puppeteer when a request is received, such as navigating to a webpage or taking a screenshot.