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
Quick Start
What File Access Enables
With--allow-file-access, the browser can:
- Navigate to file:// URLs - Open local files directly
- Load local resources - Images, scripts, stylesheets from local files
- Access other local files via JavaScript - XMLHttpRequest, fetch to file:// URLs
- Read local directories - If the file system structure is linked
src/browser.ts:1324-1328:
File URL Format
Unix/Linux/macOS
Windows
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:
test/file-access.test.ts:81-112):
Safe Usage
Only enable file access when:- You control all local files being accessed
- The files don’t contain sensitive data
- You trust the JavaScript in the local HTML files
- You’re in a sandboxed environment
- 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 theAGENT_BROWSER_ALLOW_FILE_ACCESS environment variable to enable file access by default:
src/daemon.ts:460:
Configuration File
Enable file access in your config file for persistent access:~/.agent-browser/config.json or ./agent-browser.json.
Chromium Only
File access is only supported in Chromium. Fromsrc/browser.ts:1315-1318:
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:--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. Fromsrc/browser.ts:1323-1333:
Verification Test
The test suite verifies that file access works as expected (test/file-access.test.ts:35-58):