Skip to content

Conversation

@IlyaSemenov
Copy link
Contributor

ofetch crashes in Chrome 49 (which is the latest available Chrome on Windows XP which is still relevant in certain GovTech) with this message:

Failed to construct 'Headers': No matching constructor signature.

This is because older Chrome didn't treat new Headers(undefined) as new Headers().

This PR fixes this inconvenience with no noticeable burden for modern browsers (or code base readability).

Related: whatwg/fetch#185

@codecov
Copy link

codecov bot commented Apr 27, 2023

Codecov Report

Merging #235 (26a3eda) into main (e27b50d) will increase coverage by 0.03%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #235      +/-   ##
==========================================
+ Coverage   86.26%   86.29%   +0.03%     
==========================================
  Files           5        5              
  Lines         415      416       +1     
  Branches       68       69       +1     
==========================================
+ Hits          358      359       +1     
  Misses         57       57              
Impacted Files Coverage Δ
src/fetch.ts 89.27% <100.00%> (+0.04%) ⬆️

@pi0 pi0 changed the title fix: prevent crash on Chrome 49 fix: pass empty object to headers initializer to prevent crash on chrome 49 Jun 6, 2023
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@pi0 pi0 merged commit 5c24342 into unjs:main Jun 6, 2023
pi0 added a commit to DennisBetawerk/ofetch that referenced this pull request Jun 6, 2023
ConnorBerghoffer added a commit to ConnorBerghoffer/ofetch that referenced this pull request Nov 19, 2025
The mergeHeaders function was passing undefined directly to new Headers() which crashes in Chrome 49 and other legacy browsers that don't support that syntax. Now defaults to empty object when input is undefined, matching the fix from unjs#235.

Fixes unjs#493
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants