You can check the status code of a page request in Puppeteer by accessing the response object in the page's main frame and then getting the status code property from that object. Here's an example code snippet:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const response = await page.goto('https://example.com');
const statusCode = response.status();
console.log(`Status code: ${statusCode}`);
await browser.close();
})();
In this code snippet, we first launch a new Puppeteer browser instance and create a new page. We then make a request to the URL "https://example.com" using the page.goto()
method and store the response in the response
variable. Finally, we get the status code of the response using the status()
method and log it to the console.