function sensaCollectPageMeta() {
  const selection = window.getSelection?.()?.toString().trim() || "";
  const activeElement = document.activeElement;
  const activeInfo =
    activeElement && activeElement !== document.body
      ? {
          tag: activeElement.tagName,
          id: activeElement.id || "",
          classes: String(activeElement.className || ""),
          text: sensaNormalizeText(activeElement.textContent || activeElement.value || ""),
          placeholder: activeElement.getAttribute?.("placeholder") || ""
        }
      : null;

  return {
    page: {
      title: document.title,
      url: location.href,
      hostname: location.hostname,
      description:
        document.querySelector('meta[name="description"]')?.getAttribute("content") || ""
    },
    selection,
    activeElement: activeInfo,
    interaction: {
      scroll: {
        x: window.scrollX,
        y: window.scrollY,
        viewportWidth: window.innerWidth,
        viewportHeight: window.innerHeight
      },
      readyState: document.readyState
    },
    timestamp: new Date().toISOString()
  };
}
