Skip to main content

Overview

The --allow-file-access flag enables agent-browser to open and interact with local files using file:// URLs. This is useful for:
  • Viewing local PDFs
  • Testing local HTML files
  • Accessing local documentation
  • Scraping content from local files
Note: This feature is Chromium-only and disabled by default for security.

Quick Start

What File Access Enables

With --allow-file-access, the browser can:
  1. Navigate to file:// URLs - Open local files directly
  2. Load local resources - Images, scripts, stylesheets from local files
  3. Access other local files via JavaScript - XMLHttpRequest, fetch to file:// URLs
  4. Read local directories - If the file system structure is linked
From src/browser.ts:1324-1328:
These Chromium flags are added to the browser launch arguments when file access is enabled.

File URL Format

Unix/Linux/macOS

Windows

Important: Use three slashes after file: on Unix/macOS, and include the drive letter on Windows.

Security Implications

Why Disabled by Default

File access is disabled by default because it allows JavaScript to read local files, which can expose:
  • Private documents
  • Configuration files with credentials
  • Source code and intellectual property
  • System information

What Can Be Accessed

With --allow-file-access, a malicious local HTML file could:
From the test suite (test/file-access.test.ts:81-112):

Safe Usage

Only enable file access when:
  1. You control all local files being accessed
  2. The files don’t contain sensitive data
  3. You trust the JavaScript in the local HTML files
  4. You’re in a sandboxed environment
Never enable file access for:
  • Untrusted local HTML files
  • Files downloaded from the internet
  • Multi-user systems where other users have local files

Use Cases

PDF Viewing

View and screenshot local PDFs:

Local HTML Testing

Test locally-built HTML files before deploying:

Documentation Scraping

Extract content from local documentation:

Local File Workflows

Combine with other tools to process local files:

Environment Variable

Use the AGENT_BROWSER_ALLOW_FILE_ACCESS environment variable to enable file access by default:
From src/daemon.ts:460:

Configuration File

Enable file access in your config file for persistent access:
Save to ~/.agent-browser/config.json or ./agent-browser.json.

Chromium Only

File access is only supported in Chromium. From src/browser.ts:1315-1318:
Attempting to use file access with Firefox or WebKit will fail:

Compatibility

Works With

  • Headless mode (default)
  • Headed mode (--headed)
  • Custom user agents (--user-agent)
  • Custom browser arguments (--args)
  • Screenshots and PDFs

Does Not Work With

  • Firefox (--browser firefox)
  • WebKit (--browser webkit)
  • (File access is Chromium-specific)

Testing

The test suite includes comprehensive file access tests (test/file-access.test.ts):

Without File Access (Default)

With File Access

Common Issues

Path Format Errors

Relative Paths

Windows Drive Letters

Permission Denied

If the file exists but can’t be read:

Alternatives

Local Web Server

For testing local HTML without security risks, use a local web server:
This avoids the need for --allow-file-access while still testing local files.

Temporary Directory

Copy trusted files to a temporary directory and enable file access only for that directory:

Implementation Details

File access is implemented by adding Chromium command-line flags during browser launch. From src/browser.ts:1323-1333:
These flags are passed to Playwright’s browser launcher, which forwards them to the Chromium process.

Verification Test

The test suite verifies that file access works as expected (test/file-access.test.ts:35-58):
This confirms that navigation works but cross-file access is blocked without the flag.