Assets

Serve AssetMapper output and public files directly while browser requests remain inside the Symfony test process.

The bundle serves common static assets directly during an in-process browser test. CSS, JavaScript, fonts, and images can reach the real browser without opening a web server or routing every file through HttpKernel.

How an asset request is resolved

For an intercepted host, the asset bridge handles GET and HEAD requests whose path starts with a configured prefix:

  1. AssetMapperProxy looks up the public path in Symfony AssetMapper when it is installed.
  2. FilesystemProxy searches the configured public roots.
  3. The asset is returned with its content type, size, cache policy, and last-modified metadata.
  4. When neither locator resolves the path, the request continues through the Symfony kernel.

AssetMapper is optional. The filesystem path works for applications that publish files directly under public/ or another declared root.

Default configuration

yaml
# config/packages/test/playwright.yaml
playwright:
    assets:
        public_roots:
            - '%kernel.project_dir%/public'
        prefixes:
            - '/assets'
            - '/build'
            - '/_framework/ux'
        disable_cache: true

public_roots are filesystem directories. prefixes are URL path prefixes. A request must match a prefix before the locators try to resolve it.

Add an application asset root

Add roots and prefixes when the test build publishes files outside the default directory:

yaml
playwright:
    assets:
        public_roots:
            - '%kernel.project_dir%/public'
            - '%kernel.project_dir%/var/test-assets'
        prefixes:
            - '/assets'
            - '/build'
            - '/test-assets'

This is useful for generated bundles, fixtures, or a frontend build prepared specifically for the browser suite.

AssetMapper behavior

The AssetMapper locator resolves public paths, including mapped and fingerprinted paths. When an asset carries compiled inline content, that content is served to the browser. Otherwise the locator can use its source file and metadata.

The browser receives the MIME type expected for the file. TypeScript-family assets are served as JavaScript, and common web formats use Symfony Mime when it is available.

Cache policy

The default disable_cache: true response includes a no-store policy. Every test therefore sees the current file generated by the suite.

Set it to false for scenarios that deliberately test browser caching or service-worker behavior:

yaml
playwright:
    assets:
        disable_cache: false

The bridge then sends an immutable cache policy and includes Last-Modified when the locator provides it.

Diagnose asset routing

Enable focused bundle logging to see whether a request was served as an asset or passed to the kernel:

yaml
playwright:
    debug_logging: true

If a file reaches the kernel, compare its URL with prefixes, then confirm that AssetMapper exposes the public path or that the file exists below a configured root.