feat: add --allow-file-access flag for file:// URL support (#375)
* feat: add --allow-file-access flag for file:// URL support Adds the ability to open and interact with local files using file:// URLs. This enables use cases like viewing local PDFs, testing local HTML files, and allowing JavaScript to access other local files via XHR. The flag adds Chromium's --allow-file-access-from-files and --allow-file-access launch arguments. Only supported in Chromium browsers. Fixes #345 * fix: add cli_allow_file_access tracking to prevent spurious warning When --allow-file-access is set via AGENT_BROWSER_ALLOW_FILE_ACCESS env var (not CLI), don't warn about the flag being ignored when daemon is already running.
This commit is contained in:
@@ -339,6 +339,7 @@ The `-C` flag is useful for modern web apps that use custom clickable elements (
|
||||
| `--headed` | Show browser window (not headless) |
|
||||
| `--cdp <port>` | Connect via Chrome DevTools Protocol |
|
||||
| `--ignore-https-errors` | Ignore HTTPS certificate errors (useful for self-signed certs) |
|
||||
| `--allow-file-access` | Allow file:// URLs to access local files (Chromium only) |
|
||||
| `--debug` | Debug output |
|
||||
|
||||
## Selectors
|
||||
@@ -496,6 +497,27 @@ export async function handler() {
|
||||
}
|
||||
```
|
||||
|
||||
## Local Files
|
||||
|
||||
Open and interact with local files (PDFs, HTML, etc.) using `file://` URLs:
|
||||
|
||||
```bash
|
||||
# Enable file access (required for JavaScript to access local files)
|
||||
agent-browser --allow-file-access open file:///path/to/document.pdf
|
||||
agent-browser --allow-file-access open file:///path/to/page.html
|
||||
|
||||
# Take screenshot of a local PDF
|
||||
agent-browser --allow-file-access open file:///Users/me/report.pdf
|
||||
agent-browser screenshot report.png
|
||||
```
|
||||
|
||||
The `--allow-file-access` flag adds Chromium flags (`--allow-file-access-from-files`, `--allow-file-access`) that allow `file://` URLs to:
|
||||
- Load and render local files
|
||||
- Access other local files via JavaScript (XHR, fetch)
|
||||
- Load local resources (images, scripts, stylesheets)
|
||||
|
||||
**Note:** This flag only works with Chromium. For security, it's disabled by default.
|
||||
|
||||
## CDP Mode
|
||||
|
||||
Connect to an existing browser via Chrome DevTools Protocol:
|
||||
|
||||
Reference in New Issue
Block a user