const browser = require('../browser');

module.exports = async ({ selector = 'body' }) => {
  await browser.start();
  const p = await browser.ensurePage();

  const text = await p.evaluate((sel) => {
    const el = document.querySelector(sel);
    if (!el) return null;

    const t = el.innerText || el.textContent || '';
    return t.trim() || null;
  }, selector);

  return {
    success: true,
    action: "get_text",
    selector,
    text
  };
};
