> For the complete documentation index, see [llms.txt](https://docs.bugbug.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.bugbug.io/editing-tests/file-viewer.md). Agents can also search and read this documentation through its [MCP server](https://docs.bugbug.io/~gitbook/mcp).

# File Viewer

Open application files in tests, record assertions, and understand supported previews and download limits.

Use **Open file in viewer** to check a PDF invoice, spreadsheet, export or another supported file produced by your application. The action opens a viewer tab; ordinary text assertions then check its contents. You can also inspect files manually in the standalone viewer.

## Open a file in a test

The action requires **CORE or higher**, the feature enabled for your project, and a compatible extension (**14.29.0 or newer**). If it is missing, check project availability and [update the extension](https://docs.bugbug.io/troubleshooting/updating-chrome-extension.md).

1. Start recording on the application page. Record login and the steps that make the file available.
2. If a button or form downloads the file, click it before entering **Assert file**. If a normal click reveals an embedded preview, reveal it first.
3. Choose **Assert file** in the recorder menu, then select **Element** or **Downloaded file**.
4. Select the file source as described below and wait for the viewer to report that its text, cells or metadata are ready for assertions.
5. Choose **Add assert** and click the text, field or cell to check. For CSV and JSON, choose **Table** or **Source** first.
6. Return to the application tab when needed and keep the recorded [Switch context](https://docs.bugbug.io/editing-tests/tabs-and-iframes.md) step.

### Choose the source

| Source              | When to use it                                     | What to select                                                                              |
| ------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| **Element**         | The page exposes a file link or embedded preview   | Click the link, an icon inside it, or the `iframe`, `embed` or `object` displaying the file |
| **Downloaded file** | A link, button or form already downloaded the file | Check the displayed name and click **Open downloaded file**                                 |

When the panel opens, **Downloaded file** is selected if BugBug identifies a download from the current recording; otherwise **Element** is selected. You can switch to Element to check an embedded PDF even when an earlier download exists. Switching sources does not record a step. Your choice is retained while the menu stays open; reopening it checks for downloads again.

With no identified download, **Open downloaded file** is disabled. Return to normal recording, trigger the download, and reopen Assert file. During preparation, the source switch is disabled.

In Element mode, page elements are highlighted before their source is checked. Clicking an unsupported element shows a message and keeps the mode available for another choice. A JavaScript-only link or button does not expose a file URL: use its downloaded file or the preview it reveals instead. While a file is being prepared, the label shows **Downloading file…**. Further clicks do not start another selection; leaving the mode cancels it.

The downloaded-file preview uses the specific file shown in the menu. Replay resolves the latest identifiable download from that test run, so keep the step that triggers it before the viewer step. If previewing fails after the step was saved, the menu says so; the recorded step remains in the test.

You can also add the action in the [step editor](https://docs.bugbug.io/editing-tests/manually-creating-the-test.md). Set **File source** to **Element on page** and provide its selectors, or to **Downloaded file**. The step stores the source choice, not a copy of the file, its temporary URL or the recording's download ID.

### Choose what to assert

Opening succeeds when the viewer has read and mounted the file content. Add an [Element has text](https://docs.bugbug.io/editing-tests/assertions.md) assertion to verify the expected value. A recorded assertion uses **is** for the clicked element's full text; choose **contains** or **matches regex** when appropriate.

For an invoice, select the PDF line containing both the item description and its price. Checking the whole document for a price can match another item. Text at the same vertical position is grouped into one line, so a nearby box or a second column may become part of the same assertion. Wrapped cells may occupy several lines. Check the recorded text before relying on it.

PDF line selectors identify the page and line independently of the asserted text. A text change can therefore produce an assertion mismatch rather than a missing-element error. Inserting or reordering pages or lines can still change their positions. For tables and JSON, prefer a cell or field; array indices and row positions can change when records are reordered.

### Download access and limitations

Element sources are read using the browser session of the source page. Keep login steps before the viewer step. A network or cross-origin failure for an HTTP(S) link can be retried from the extension's background context. HTTP status errors and size-limit errors are reported directly.

Downloaded-file sources must come from the test or recording session. Downloads from unrelated tabs are excluded. BugBug must identify one file to open and does not guess between several matches.

| Download situation                                                                    | Behaviour                                                                  |
| ------------------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
| BugBug captured the original response                                                 | The viewer reuses those bytes, including POST exports and single-use links |
| The response was not captured and the original HTTP request was GET                   | BugBug downloads the URL again using the browser session                   |
| The response was not captured and the HTTP method was POST, another method or unknown | The step reports `FILE_DOWNLOAD_FAILED` without repeating the request      |
| A `data:` URL supplied the download                                                   | BugBug reads the embedded bytes directly, with the same file-size limits   |
| A `blob:` URL supplied the download                                                   | The creating page must remain open and the blob must still be readable     |

Capturing a copy requires a recognized, uncompressed download response with a declared size within **40 MB**. Compressed responses, such as gzip or Brotli, and responses without a declared size are downloaded normally by Chrome. They use the GET fallback when eligible. For an uncaptured POST export, ask your application developer to send an uncompressed response with `Content-Length`, or provide a direct GET download link.

A GET retry can fail when a single-use link expires or the session changes. BugBug rejects an HTML page returned instead of a previously downloaded non-HTML file. Element sources can still open a linked HTML page as source, so following assertions must verify the expected document.

Downloads opened in a new tab by a link, form or `window.open` are associated with the test when the new tab was opened from a session tab. If its response could not be captured, the same verified-GET rule applies. A POST form that opens a download in a new tab can require submitting in the same tab so BugBug can capture its response.

Temporary URLs must be recreated by the application during each replay. A successful manual download does not guarantee that its original request can be repeated safely.

### Results and errors

Successful run details contain the file name, byte size, page count and readability warnings. In the test editor, these values describe the last run. They do not mean the expected text was found: that is checked by the following assertions.

A PDF with no text layer, unreadable text or missing characters can still open successfully with a warning. The viewer does not perform OCR, so text assertions on a scan may fail even when the page looks correct.

* **`FILE_NOT_DOWNLOADED`:** no session download was observed. Check the preceding download step.
* **`FILE_DOWNLOAD_NOT_IDENTIFIED`:** a download was observed, but BugBug could not identify one usable file. Check that it finishes successfully and is triggered only once.
* **`FILE_DOWNLOAD_FAILED`:** downloading or safely reusing the response failed. Check the detailed message, access and the fallback limitations above.

See [File viewer errors](https://docs.bugbug.io/debugging-tests/error-codes.md#file-viewer-errors) for the full list, including unsupported formats, parsing failures and size limits.

### API, MCP and YAML

The action name is `openFileInViewer`. API v2, SDK and MCP use `fileViewerSource`; test YAML uses `file_viewer_source`. Choose `element` (the default) with source-element selectors, or `download` without selectors. The same plan and project availability requirements apply when creating or importing tests. There is no file-specific viewer-version setting.

## Open a file manually <a href="#open-a-file" id="open-a-file"></a>

1. Open [BugBug File Viewer](https://bugbug-file-viewer.com/).
2. Drag a file onto the page, or click **Choose file**.
3. Wait for **Text ready for assertions**, **Cells ready for assertions** or **Metadata ready for assertions**, depending on the format. Unreadable files show an error.

Use **Open file** in the top bar to choose another file. Files are read in your browser and are not uploaded by the viewer. This does not add them to the project's [Files library](https://docs.bugbug.io/organizing-tests/files.md), which stores files for upload steps.

## What you can preview

| Format                    | Preview                                                                              |
| ------------------------- | ------------------------------------------------------------------------------------ |
| PDF                       | Document pages and positioned text lines                                             |
| CSV                       | Table with first-row column headers and original source                              |
| XLS / XLSX                | Worksheet grids and sheet selection; saved formula values without recalculation      |
| DOC                       | Readable Word 97–2003 content with simplified formatting                             |
| DOCX                      | Headings, paragraphs, lists, tables and embedded images; layout may differ from Word |
| JSON                      | Original source; table for arrays of flat records                                    |
| HTML                      | Inactive HTML source, without scripts or external resources                          |
| YAML / YML                | Validated source with original formatting                                            |
| SQL                       | Source without query execution                                                       |
| XML                       | Inactive source without external resources                                           |
| TXT                       | Plain text with original formatting                                                  |
| PNG, JPEG, GIF, WebP, SVG | Image preview, dimensions and metadata; no text extraction                           |
| MP3, WAV, Ogg audio       | Audio controls and metadata, subject to browser codec support                        |
| MP4, WebM                 | Video controls and metadata, subject to browser codec support                        |

Every format has a collapsed **Metadata** section with the available file properties. Office previews do not execute macros or external links and do not reproduce the original application's full formatting or pagination.

Use **Table** for CSV rows and flat JSON records. Use **Source** when exact source text matters. Source preserves whitespace and line endings; JSON table numbers preserve their original notation. Nested JSON records use source view.

## Formats and limits

The test step reads files up to **40 MB**. The standalone viewer has a **50 MB** global limit, with stricter limits for some formats. A file that opens manually can therefore exceed the step's limit.

Text previews allow up to **10 MB**, **100,000 source lines** and **50,000 CSV cells**. PDFs allow up to **500 pages**. Office formats have additional size and structure budgets. See [Formats and limits](https://bugbug-file-viewer.com/formats/) for the current values and sample files.

Accepted large files may appear without syntax colors. Long logical lines wrap without changing their text. Files above the applicable budgets are rejected rather than truncated. PDF text readiness does not guarantee that every lazily rendered page canvas has finished drawing.

## FAQ

<details>

<summary>Can an AI agent help inspect a file?</summary>

If your browser and agent support WebMCP, the agent can inspect a ready file and switch its table/source view. Open the file first. Text returned to the agent is shared with that agent.

</details>

<details>

<summary>Why does my PDF have no readable text?</summary>

It may be a scan or an image. The viewer does not recognize text in images. Password-protected PDFs are also unsupported; use an unprotected copy.

</details>

<details>

<summary>Why is my JSON or YAML rejected?</summary>

Check that the file is valid. YAML must not contain duplicate keys in the same mapping.

</details>

<details>

<summary>Why does my CSV not appear as a table?</summary>

Its filename must end in `.csv`. Commas in a text or SQL file do not identify it as CSV.

</details>

<details>

<summary>Why does HTML show code instead of a page?</summary>

The viewer shows HTML as source. It does not render active HTML, execute scripts or load the file's external resources.

</details>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.bugbug.io/editing-tests/file-viewer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
