Skip to content

WebSocket domain filter throws TypeError on relative URLs (e.g. webpack HMR) #764

@classiemilio

Description

@classiemilio

Description

When using allowedDomains with a dev server that uses webpack, the domain filter's _checkUrl() function throws TypeError: Failed to construct 'URL': Invalid URL on relative URLs like /__webpack_hmr (webpack's hot module reloading endpoint).

Root Cause

In src/domain-filter.ts (and the corresponding inline script in cli/src/native/network.rs), the WebSocket URL is parsed with:

var parsed = new URL(url);

new URL(url) requires an absolute URL. Relative paths (e.g. /__webpack_hmr) need a base URL to resolve against, otherwise the constructor throws a TypeError.

Steps to Reproduce

  1. Configure allowedDomains in agent-browser
  2. Run a webpack dev server (or any setup that opens WebSocket connections with relative URLs like /__webpack_hmr)
  3. Observe TypeError: Failed to construct 'URL': Invalid URL in the console

Expected Behavior

Relative URLs should be resolved against the current page origin (location.href) without throwing an error.

Affected Files

  • src/domain-filter.ts_checkUrl() function
  • cli/src/native/network.rs — inline WebSocket filter script

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions