Skip to content

Send page map and page map json with DOM#673

Open
mahbd wants to merge 2 commits intodevfrom
task-2269-handle-large-dom
Open

Send page map and page map json with DOM#673
mahbd wants to merge 2 commits intodevfrom
task-2269-handle-large-dom

Conversation

@mahbd
Copy link
Collaborator

@mahbd mahbd commented Mar 8, 2026

PR Type

Feature

PR Checklist

  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • A changelog entry has been made.
  • Version number has been updated.
  • Required modules have been added to respective "requirements*.txt" files.
  • Relevant Test Cases added to this description (below).
  • (Team) Label with affected action categories and semver status.

Overview

This PR introduces the functionality to capture and send the DOM structure alongside a computed page map (both raw text and structured JSON) to the backend (/node_ai_contents).

This addresses the need for richer context when analyzing pages, especially concerning performance and iframe complexity, as hinted by previous fixes related to performance and iframe inspection.

Key changes in background.js:

  1. Asynchronous Sending with Debouncing and Hashing: The node_ai_contents API call is now debounced globally for each tab (2000ms) to prevent excessive calls. Before sending, a SHA-256 hash of the combined DOM, page map, and page map JSON is calculated. If the hash matches the previous send for that tab, the request is skipped, addressing performance issues related to constantly sending unchanged content.
  2. Content Payload Update: The payload sent now includes page_map and page_map_json alongside dom.

Key changes in inspect.js:

  1. Page Map Extraction: A new script, page_map_extractor.js, is injected and executes extractPageMapData() periodically. This function generates an ordered list of visible, interactive, and text-contextual elements, along with their computed XPath/attributes, compiling it into page_map_json (structured data) and page_map (human-readable text summary).
  2. Iframe Guard: Added a check in inspect.js to ensure DOM extraction only runs on the main window (window.top === window.self) to prevent conflicts from tracking pixels or nested content injection.

This enhancement improves the quality and efficiency of data sent to the AI backend by providing a structured map of the page context.

Test Cases

  • Verify that DOM submissions are skipped if the combined DOM + Page Map content has not changed (check console logs for "skipped").
  • Verify that a new file, page_map_extractor.js, is included in the content script injection.
  • Verify that DOM extraction does not run inside iframes.

@mahbd
Copy link
Collaborator Author

mahbd commented Mar 8, 2026

📚 $\text{Stack Overview}$

Pulls submitted in this stack:

This comment was automatically generated by st.

@mahbd mahbd marked this pull request as ready for review March 8, 2026 05:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant