Skip to content

Commit 5c944d4

Browse files
authored
Merge pull request #256 from qgustavor/next
Release - v1.3.9
2 parents 9b52011 + 733b72e commit 5c944d4

File tree

2 files changed

+14
-28
lines changed

2 files changed

+14
-28
lines changed

lib/api.mjs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,12 @@ class API extends EventEmitter {
227227
}
228228

229229
static getShouldAvoidUA () {
230-
// It's not possible to detect when a browser fails CORS requests by defining an user-agent
231-
// using feature detection, so the alternatives were using user-agent detection
232-
// (which is not ideal because might not catch Firefox forks) or hacks.
233-
234-
// This library uses hacks.
235-
// Those were found using BrowserStack and the following tests: https://codepen.io/qgustavor/pen/JjqqBPp
236-
237-
let headersErr
238-
try {
239-
globalThis.Headers()
240-
} catch (err) {
241-
headersErr = err.message
242-
}
243-
return !((globalThis.fetch + '').length === 38 && headersErr.includes('Headers'))
230+
// The only case where we need to avoid setting an user-agent is on browsers
231+
// as it would lead to CORS issues as user-agent isn't a whitelisted header
232+
// (as it's not included on Access-Control-Allow-Headers from MEGA responses)
233+
// but the only browser that causes issues from that is Firefox as it is the
234+
// only one that allows JavaScript overriding the user-agent.
235+
return !!globalThis.navigator
244236
}
245237
}
246238

package-lock.json

Lines changed: 8 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)