unjs / unjs/ofetch

Crash in legacy browsers on new Headers(undefined)

Open
#493 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
TypeScript
Stars
5.4k
Forks
195
PR merge metrics
No merged PRs in 30d

Description

Environment

ofetch 1.4.1
Chrome 49

Reproduction
Describe the bug

Similarly to the problem that was originally resolved in #235, the library now crashes here in legacy browsers:

https://github.com/unjs/ofetch/blob/c817be86e8758ed7e6a05d2589f4b318f1f0b38e/src/utils.ts#L116

due to new Headers(undefined) not being supported in runtime.

The code could be easily updated in a similar fashion, but I'm not sure if it should be? In my project, I decided to add a polyfill wrapper class around Headers instead of patching ofetch. Maybe we should actually revert #235 and document the workaround?

Additional context
Polyfill
// Legacy browsers crash on new Headers(undefined)
// See https://github.com/unjs/ofetch/pull/235

try {
  // eslint-disable-next-line no-new
  new Headers(undefined)
} catch (
  // eslint-disable-next-line unused-imports/no-unused-vars
  _err
) {
  // eslint-disable-next-line no-global-assign
  Headers = (function (Base) {
    return class Headers extends Base {
      constructor(init) {
        super(init || {})
      }
    }
  })(Headers)
}
Logs

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at src/utils.ts around line 116 and compare the Headers handling with the resolution described in issue #235. Reproduce the Chrome 49 failure, then determine whether the supported fix is to avoid new Headers(undefined) or to document the polyfill workaround; confirm the chosen behavior in legacy browsers.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.