8000 Crash in legacy browsers on new Headers(undefined) · Issue #493 · unjs/ofetch · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Crash in legacy browsers on new Headers(undefined) #493
Open
@IlyaSemenov

Description

@IlyaSemenov

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:

return new Headers(input);

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0