> For the complete documentation index, see [llms.txt](https://gaffa.dev/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://gaffa.dev/docs/features/browser-requests/actions/capture-dom.md).

# Capture DOM

**Type:** `capture_dom`

This action will capture and return the site's raw DOM, which you can then extract data from on your end.

For common AI scenarios, you may find that this returns too much data, so we have provided a [`generate_simplified_dom`](/docs/features/browser-requests/actions/generate-simplified-dom.md) , an action that distils the DOM to only the important elements.

<details>

<summary><strong>Tips for using <code>cature_dom</code> action</strong></summary>

* Use it when you want to parse the page yourself with a traditional HTML library such as BeautifulSoup, lxml, or Cheerio.
* It can also be used for debugging. When a selector isn't matching, the raw DOM shows you what's actually on the page.
* Use it when you need something the other actions strip out, like inline scripts, `data-` attributes or full link URLs.
* Don't send the output to an LLM. Use [`generate_simplified_dom`](/docs/features/browser-requests/actions/generate-simplified-dom.md) or [`generate_markdown`](/docs/features/browser-requests/actions/generate-markdown.md) instead, which carry the same information for far fewer tokens.
* It captures the page as it is at that point in the run, so you can use it multiple times to compare the state before and after an interaction.
* If content is missing from the capture, the page probably hadn't finished loading. Add a [`wait`](/docs/features/browser-requests/actions/wait.md) before it.

</details>

### Parameters

See [universal parameters](/docs/features/browser-requests/actions.md#universal-parameters).

### Usage

Capture the raw DOM of the current page

```
"actions": [
    {
      "type": "capture_dom"
    }
]
```

### Example Output

{% file src="/files/l8xETXQjit3lKZXjIN2q" %}

### FAQs

#### When do I use the capture\_dom action?

Use it when you want to parse the page yourself with a library like BeautifulSoup, or when you need scripts, attributes and link query strings that the simplified and Markdown outputs remove. See our[ guide to scraping tables with Python](https://gaffa.dev/blog/how-to-scrape-a-table-with-python-\(the-easy-way\)).

#### What does capture\_dom action return?

It returns the page's raw DOM as the browser rendered it, including scripts, styles and every attribute. This is the page after JavaScript has run, not the original server HTML.

#### Why is content missing from my capture\_dom output?

The action probably ran before the page finished loading. Add a [`wait`](/docs/features/browser-requests/actions/wait.md) action with a selector for the content you're expecting, so Gaffa captures the page once it's there.

#### When should I use generate\_simplified\_dom instead of capture\_dom?

Use [`generate_simplified_dom`](/docs/features/browser-requests/actions/generate-simplified-dom.md) whenever the output goes to an LLM, or you're looking for `selectors`. It keeps the page structure but removes the scripts and styling that make raw DOM so large. See our[ guide to simplifying a webpage DOM](https://gaffa.dev/blog/how-to-extract-and-simplify-a-webpage-dom-with-gaffa).

#### Why is my capture\_dom output so big?

Raw DOM includes all scripts and styles on the page. Use [`generate_simplified_dom`](/docs/features/browser-requests/actions/generate-simplified-dom.md) to strip those out, or [`capture_element`](/docs/features/browser-requests/actions/capture-element.md) with a selector to capture only the part you need.

#### How do I capture only part of the page with capture\_dom action?

Use [`capture_element`](/docs/features/browser-requests/actions/capture-element.md) with a selector instead. It gives you the same raw HTML, but only for the element you point it at.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://gaffa.dev/docs/features/browser-requests/actions/capture-dom.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
