Skip to content

Preserve the original request URL in "onUnhandledRequest" warnings #2125

@kettanaito

Description

@kettanaito

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 18 or higher

Node.js version

v20.11.0

Reproduction repository

Always specify repros. Don't follow my lead.

Reproduction steps

  1. Set up MSW in the browser.
  2. Configure the onUnhandledRequest callback:
await worker.start({
  onUnhandledRequest(request, print) {
    console.log('URL:', request.url)
    if (/\.(css|js|json|png|jpg|gif)$/.test(request.url)) {
      return
    }

    print.warning()
  },
})
  1. Make a request like /fo/bar/?t=123

Current behavior

MSW prints a clean URL, making it hard to understand why my custom onUnhandledRequest logic is not matching this request:

Screenshot 2024-04-05 at 15 45 08

Expected behavior

MSW preserves the unhandled request URL as-is, which includes keeping its query parameters and fragments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomersscope:browserRelated to MSW running in a browserscope:nodeRelated to MSW running in Node

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions