Open
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:
Line 116 in c817be8
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)
}