prozy-anywhere / test.js
ka1kuk's picture
Upload 6 files
1f4041b
raw
history blame
1.27 kB
const app = require("express")();
let chrome = {};
let puppeteer;
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) {
chrome = require("chrome-aws-lambda");
puppeteer = require("puppeteer-core");
} else {
puppeteer = require("puppeteer");
}
app.get("/api", async (req, res) => {
let options = {};
if (process.env.AWS_LAMBDA_FUNCTION_VERSION) {
options = {
args: [...chrome.args, "--hide-scrollbars", "--disable-web-security"],
defaultViewport: chrome.defaultViewport,
executablePath: await chrome.executablePath,
headless: true,
ignoreHTTPSErrors: true,
};
}
try {
let browser = await puppeteer.launch(options);
let page = await browser.newPage();
await page.goto("https://liaobots.work/");
await page.click('label.button');
await page.waitForNavigation();
await page.waitForTimeout(2000);
// Execute JavaScript code in the context of the page
const value = await page.evaluate(() => {
// Retrieve the value from localStorage
return localStorage.getItem('authCode');
});
res.send(value);
} catch (err) {
console.error(err);
return null;
}
});
app.listen(process.env.PORT || 3000, () => {
console.log("Server started");
});
module.exports = app;