41 lines
1.1 KiB
JavaScript
41 lines
1.1 KiB
JavaScript
const { firefox } = require('playwright');
|
|
const fs = require('fs');
|
|
|
|
async function browse(url) {
|
|
const browser = await firefox.launch({ headless: true });
|
|
const context = await browser.newContext();
|
|
const page = await context.newPage();
|
|
|
|
try {
|
|
await page.goto(url, { waitUntil: 'networkidle', timeout: 30000 });
|
|
|
|
// Wait a bit for JS to render
|
|
await page.waitForTimeout(2000);
|
|
|
|
const screenshot = await page.screenshot({ type: 'jpeg', quality: 80 });
|
|
const text = await page.innerText('body');
|
|
const title = await page.title();
|
|
|
|
const result = {
|
|
title: title,
|
|
text: text.substring(0, 5000), // Limit text to 5k chars
|
|
screenshot: screenshot.toString('base64')
|
|
};
|
|
|
|
console.log(JSON.stringify(result));
|
|
} catch (error) {
|
|
console.error(JSON.stringify({ error: error.message }));
|
|
process.exit(1);
|
|
} finally {
|
|
await browser.close();
|
|
}
|
|
}
|
|
|
|
const url = process.argv[2];
|
|
if (!url) {
|
|
console.error("No URL provided");
|
|
process.exit(1);
|
|
}
|
|
|
|
browse(url);
|