Here's a service I'm running on a Debian 10 VPS:
require("dotenv").config();
const express = require("express");
const puppeteer = require("puppeteer");
const app = express();
app.use(express.json());
app.post("/create-inbox", (req, res) => {
if (!req.body["firstName"] || !req.body["lastName"]) return res.status(400).json({ Error: "firstName and lastName are required." });
let firstName = req.body["firstName"];
let lastName = req.body["lastName"];
res.status(202).json({ firstName: firstName, lastName: lastName});
createInbox(firstName, lastName);
})
app.listen(process.env.PORT);
async function createInbox(firstName, lastName) {
const browser = await puppeteer.launch({ headless: true });
console.log(`Browser opened`);
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(0);
await page.setDefaultTimeout(0);
await page.goto("https://app.mailparser.io/account/login", {
waitUntil: 'domcontentloaded'
});
console.log(`Loaded ${page.url()}`);
await page.type("#email", process.env.MP_ACCT);
await page.type("#password", process.env.MP_PASS);
await page.click("#start-free-sub");
await page.waitForNavigation({ waitUntil: "domcontentloaded" });
console.log(`Loaded ${page.url()}`);
await page.click("#dashboard_inbox_add");
await page.type("input[name='label']", `${firstName} ${lastName}`);
await page.select("select[name='inbox_category_id']", "3015");
// hangs here on second run
await Promise.all([
page.waitForNavigation({ waitUntil: "domcontentloaded" }),
page.click("#btn_add_address_save"),
]);
console.log("after save");
await browser.close();
console.log(`Browser closed`);
}
This seems to run just fine the first time I start the service, but when I try to use the route again it hangs right at the Promise.all(...)
. console.log("after save")
will only show up after the first run.
Promise.all(...)
was the solution proposed here: Puppeteer hanging on page.click()
As well as the official solution in the Puppeteer documentation
I'm at a loss for what to try next.