1
Fork 0

run browser headed to support checks requiring you to click something

This commit is contained in:
Conduitry 2023-03-23 21:54:45 -04:00
parent d3325eccb4
commit 49beedc24d
1 changed files with 5 additions and 4 deletions

View File

@ -5,18 +5,19 @@ if (process.argv.length !== 3) {
process.exit(1);
}
const browser = await firefox.launch();
const browser = await firefox.launch({ headless: false });
browser.on('disconnected', () => process.exit(1));
const context = await browser.newContext();
const page = await context.newPage();
page.on('close', () => process.exit(1));
const user_agent = await page.evaluate('navigator.userAgent');
await page.goto(`https://${process.argv[2]}`);
let cf_clearance;
for (let i = 0; i < 100 && !cf_clearance; i++) {
while (!cf_clearance) {
await new Promise(res => setTimeout(res, 100));
cf_clearance = (await context.cookies()).find(({ name }) => name === 'cf_clearance');
}
console.log(JSON.stringify({ headers: { cookie: `cf_clearance=${cf_clearance.value}`, 'user-agent': user_agent } }));
await browser.close();
process.exit(0);