const config = require('../src/config');
const { launchBrowser, createContext } = require('../src/session');
const { fetchTargetHtmlWithSession } = require('../src/fetcher');

(async () => {
  const browser = await launchBrowser({ headless: config.headless });
  const context = await createContext({ browser, sessionFile: config.sessionFile });

  const result = await fetchTargetHtmlWithSession({ context, config, targetUrl: config.targetUrl });
  console.log('HTTP status:', result.status);
  console.log('Current URL:', result.finalUrl);
  console.log('Title:', result.title);
  console.log('Auth required:', result.authRequired);
  console.log('\nHTML preview:\n');
  console.log(result.html.slice(0, 3000));

  await browser.close();
})().catch((error) => {
  console.error(error);
  process.exit(1);
});
