Introduction | browsershot-rust | Spatie       

 SPATIE  

browsershot-rust
================

spatie.be/open-source

  [Docs](https://spatie.be/docs)  [Browsershot-rust](https://spatie.be/docs/browsershot-rust/v1)  Usage  Introduction

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/browsershot-rust/v1) 

  Introduction    
- [ Introduction ](https://spatie.be/docs/browsershot-rust/v1/introduction)
- [ Support us ](https://spatie.be/docs/browsershot-rust/v1/support-us)
- [ Requirements ](https://spatie.be/docs/browsershot-rust/v1/requirements)
- [ Installation &amp; setup ](https://spatie.be/docs/browsershot-rust/v1/installation-setup)
- [ Questions and issues ](https://spatie.be/docs/browsershot-rust/v1/questions-issues)
- [ Testing ](https://spatie.be/docs/browsershot-rust/v1/testing)
- [ Changelog ](https://spatie.be/docs/browsershot-rust/v1/changelog)
- [ About us ](https://spatie.be/docs/browsershot-rust/v1/about-us)

Usage
-----

- [ Introduction ](https://spatie.be/docs/browsershot-rust/v1/usage/introduction)
- [ Creating images ](https://spatie.be/docs/browsershot-rust/v1/usage/creating-images)
- [ Creating PDFs ](https://spatie.be/docs/browsershot-rust/v1/usage/creating-pdfs)
- [ Creating HTML ](https://spatie.be/docs/browsershot-rust/v1/usage/creating-html)

Miscellaneous options
---------------------

- [ Adding extra headers to every request ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/adding-extra-headers-to-every-request)
- [ Adding extra headers to the navigational request ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/adding-extra-headers-to-the-navigational-request)
- [ Changing the language of the browser ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/changing-the-language-of-the-browser)
- [ Changing the value of a dropdown ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/changing-the-value-of-a-dropdown)
- [ Clicking on the page ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/clicking-on-the-page)
- [ Connection to a remote chromium/chrome instance ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/connection-to-a-remote-chrome-instance)
- [ Disable sandboxing ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/disable-sandboxing)
- [ Fixing cors issues ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/fixing-cors-options)
- [ Getting console output ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/getting-console-ouput)
- [ Getting failed requests ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/getting-failed-requests)
- [ Ignore HTTPS errors ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/ignore-https-errors)
- [ Passing environment variables to the browser ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/passing-environment-variables-to-the-browser)
- [ Performance ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/performance)
- [ Prevent unsuccessful responses ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/prevent-unsuccessful-responses)
- [ Sending POST requests ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/sending-post-requests)
- [ Setting an arbitrary option ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/setting-an-arbirary-option)
- [ Setting the CSS media type of the page ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/setting-the-css-media-type-of-the-page)
- [ Setting the timeout ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/setting-the-timeout)
- [ Setting the user agent ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/setting-the-user-agent)
- [ Specifying-a-proxy-server ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/specifying-a-proxy-server)
- [ Typing on the page ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/typing-on-the-page)
- [ Using a pipe instead of a WebSocket ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/using-a-pipe-instead-of-a-websocket)
- [ Using cookies ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/using-cookies)
- [ Using HTTP Authentication ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/using-http-authentication)
- [ Using url for html content ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/using-url-for-html-content)
- [ Writing options to a file ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/writing-options-to-a-file)
- [ Disabling redirects ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/disabling-redirects)
- [ Read redirect history ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/read-redirect-history)
- [ Evaluating a script before page load ](https://spatie.be/docs/browsershot-rust/v1/miscellaneous-options/evaluating-a-script-before-page-load)

 Introduction
============

###  On this page 

1. [ Local file access ](#content-local-file-access)

In all examples it is assumed that you imported this type at the top of your file

```
use spatie_browsershot::Browsershot;
```

Browsershot can read the HTML of a URL and do something with it, for example convert it to pdf

```
Browsershot::url("https://example.com").save("example.pdf")?;
```

Alternatively, you can use an arbitrary html input, using the `html` function:

```
Browsershot::html("Hello world!!").save("example.pdf")?;
```

Here are the things that Browsershot can produce for you:

- [an image](/docs/browsershot-rust/v1/usage/creating-images)
- [a PDF](/docs/browsershot-rust/v1/usage/creating-pdfs)
- [HTML](/docs/browsershot-rust/v1/usage/creating-html)

Output methods return a `Result`. Use `?` to propagate errors. Examples use hidden setup lines for imports and input variables; each example is compiled by rustdoc. Examples that navigate or write output are not run by rustdoc.

Builders consume and return themselves. Output methods borrow mutably, so you can save a screenshot and then read diagnostics from the same operation. The methods `triggered_requests`, `console_messages`, `failed_requests`, `redirect_history` and `page_errors` reuse the last operation's diagnostics when available. `output()` gives borrowed access to all of them without copying.

The output also contains `result` and `exception`. Evaluation results keep their JSON types, HTML output is a string, and binary browser output is base64-encoded. An operation error remains available in `exception` alongside the captured diagnostics.

Local file access
-----------------------------------------------------------------------------------------------------------

HTML passed to `html()` or `set_html()` cannot load local files by default. Browsershot blocks `file:` requests in Chrome, including requests from images, stylesheets, scripts and iframes. This also blocks absolute filesystem paths such as `/var/www/app/public/logo.png`, which resolve to local files when rendering HTML without a content URL, and file URLs constructed by JavaScript.

Blocked resources will not appear in the output. File URLs in HTML are blocked during rendering rather than rejected by `html()` with an exception.

HTML containing `view-source` URLs or schemeless local network paths such as `//localhost/file` and `\\localhost\file` is rejected when rendering, even if local file access is enabled. Explicit HTTP(S) URLs are still allowed.

If your trusted HTML intentionally loads local assets, you can explicitly allow local file access:

```
Browsershot::html("")
    .allow_local_file_access(true)
    .save("example.pdf")?;
```

This applies to PDFs, screenshots and HTML evaluation. You can restore the default restriction with `allow_local_file_access(false)`.

Only enable this for HTML you trust. It permits access to any local file readable by Chrome, not just assets in your application's public directory.

`html_from_file_path()` and `set_html_from_file_path()` intentionally render local HTML files and retain their existing local-resource access. `set_content_url()` still controls how relative paths are resolved, and HTTP(S) resources are not blocked by the local-file restriction. Allowing local file access does not override Chrome's own security restrictions.

Browsershot is not a sandbox for untrusted HTML. You are still responsible for validating HTML and URLs. If you render untrusted content, isolate the browser's filesystem and network access; blocking local files does not prevent requests to internal HTTP services.

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
