Skip to main content

Module scripts

Module scripts 

Source
Expand description

JavaScript payloads injected into the browser by MCP tools.

Constants§

DOC_SIZE_JS
Expression yielding the document’s scroll size as JSON, for full-page screenshots on BiDi.
DOC_TOKEN_JS
Expression (for script.evaluate) yielding the per-document token as a decimal string; creates it when the walker has not run yet.
FETCH_JS
Performs a fetch from the page context. Receives JSON-string args.
GET_CLIP_RECT_JS
Resolves a selector to a clip rectangle in document coordinates, scrolling the element into view first. Returns null when the selector matches nothing or the element has zero area (hidden / detached).
GET_DOM_JS
Serializes the DOM with shadow roots included.
GET_PAGE_TEXT_JS
Readable-text extraction for browser_get_page_text. Called as (fn)(maxChars, selectorOrNull); returns a JSON string {title, url, source, text, truncated, total_chars} or {error}.
REF_CENTER_JS
(id) → centre of the element in viewport CSS px after scrolling it into view, clipped to the viewport.
REF_CLIP_RECT_JS
(id) → the element’s border box in document coordinates (same contract as GET_CLIP_RECT_JS).
REF_TYPE_JS
(id, text, mode) with mode = fill | select | clear: focus the element, select its content (or clear it), and for fill insert text through execCommand('insertText') with a value-setter fallback that keeps framework value trackers in sync. Returns {kind, method}.
SELECT_ALL_JS
Called via Runtime.callFunctionOn with this bound to the element about to receive typed text. Selects the element’s current content so the following Input.insertText replaces it (like Playwright fill). With clear=true the content is emptied outright and input/change are dispatched, for the “type an empty string” case.
SELECT_ELEMENT_JS
Interactive element picker. Resolves with the selector string for the picked element.
SNAPSHOT_TREE_JS
The walker itself; see the header comment in the file.