const puppeteer = require('puppeteer');
const { BrowserFetcher } = puppeteer;

(async () => {
    try {
        console.log('Installing browser...');
        const browserFetcher = new BrowserFetcher({ path: './node_modules/puppeteer/.local-chromium' });
        const revision = '1045629'; // Revision from the error message or a recent stable one
        const revisionInfo = await browserFetcher.download(revision);
        console.log(`Browser downloaded to ${revisionInfo.folderPath}`);
    } catch (e) {
        console.error('Download failed:', e);
        // Fallback: try default install
        try {
            console.log("Trying default install...");
            require('child_process').execSync('npm install puppeteer', { stdio: 'inherit' });
        } catch (err) {
            console.error("Manual install failed too");
        }
    }
})();
