Skip to main content
@mcp-b/smart-dom-reader extracts interactive controls, semantic content, page structure, and ranked selectors from browser DOM trees. The package has no runtime dependencies.
Package metadata

Installation

Entry points

SmartDOMReader is both a named export and the package’s default export.

SmartDOMReader

SmartDOMReader returns one SmartDOMResult for a Document or Element. Runtime options override constructor options.
extract() defaults to the current global document. extractInteractive() forces mode: 'interactive'; extractFull() forces mode: 'full'.

ProgressiveExtractor

extractRegion() and extractContent() return null when selector has no match. When extractStructure() receives an Element, that element is reported as the main region.

Extraction modes

SmartDOMReader adds semantic output only for full. Use ProgressiveExtractor.extractStructure() and ProgressiveExtractor.extractContent() for the specialized structure and content result types.

ExtractionOptions

The public interface requires mode; every constructor and method accepts Partial<ExtractionOptions> and supplies the defaults below.

FilterOptions

ContentExtractionOptions

MarkdownFormatOptions

Result types

SmartDOMResult

Element types

Progressive result types

Selector generation

generateSelectors() sorts candidates from highest to lowest score and selects the highest-ranked CSS candidate for ElementSelector.css. The ElementSelectorCandidate.type union also contains css-path; the current generator emits generated CSS paths as class-path. Text candidates use the non-standard :contains() form as a hint and are never selected for ElementSelector.css.

Supporting classes

The formatter methods return XML-wrapped Markdown strings.

Bundle string API

The bundle-string entry point exposes an injectable IIFE string and its bundle-format version marker. After evaluating SMART_DOM_READER_BUNDLE, call:
ExtractionResult is the formatted string or { error: string }. Every argument type also accepts frameSelector? and formatOptions?. frameSelector must identify a same-origin iframe with an accessible contentDocument. The root package exports ExtractionMethod, ExtractionArgs, ExtractionResult, and the five method-specific argument types: ExtractStructureArgs, ExtractRegionArgs, ExtractContentArgs, ExtractInteractiveArgs, and ExtractFullArgs.

MCP server

The separate @mcp-b/smart-dom-reader-server package wraps the browser library with @modelcontextprotocol/server v2 and returns XML-wrapped Markdown.