elbywan / wretch

A tiny wrapper built around fetch with an intuitive syntax. :candy:
MIT License
4.83k stars 98 forks source link

Fails on Mobile Browsers #244

Closed MikeGriffinReborn closed 2 months ago

MikeGriffinReborn commented 2 months ago

Fails on a lot of the older browser such as IPad 9th generation, iPhone 11's and so forth, all still good devices, in fact the iPad 9th is still a top seller, anyway, this is the error you get:

TypeError: o.canParse is not a function. (In 'o.canParse(r)', 'o.canParse' is undefined)

jQuery.Deferred exception: o.canParse is not a function. (In 'o.canParse(r)', 'o.canParse' is undefined) @https://whiskeyniner.com/js/wretch.all.min.js:1:5331 <= HERE !!! l@https://whiskeyniner.com/js/wretch.all.min.js:1:1296 @https://whiskeyniner.com/js/w9/main-map.min.js:1:10540 e@https://whiskeyniner.com/js/JQuery.js:2:32975 @https://whiskeyniner.com/js/JQuery.js:2:33347 undefined JQuery.js:3 TypeError: o.canParse is not a function. (In 'o.canParse(r)', 'o.canParse' is undefined) (anonymous) @ JQuery.js:3

MikeGriffinReborn commented 2 months ago

I fixed it by un-minifying the code (I cannot find un-minified versions anywhere - ?) so the code isn't pretty, but basically I did this:

// BEFORE const makeBasicAuthMiddleware: (config: Config) => ConfiguredMiddleware = config => next => (url, opts) => { const _URL = config.polyfill("URL") const parsedUrl = _URL.canParse(url) ? new _URL(url) : null

// AFTER (I don't call "canParse") const makeBasicAuthMiddleware: (config: Config) => ConfiguredMiddleware = config => next => (url, opts) => { const _URL = config.polyfill("URL") const parsedUrl = null // HERE HERE !! - I just set it to null because I don't use makeBasicAuthMiddleware() at all in my code

MikeGriffinReborn commented 2 months ago

PS: I used BrowserStack.com to run it on live devices in order to debug this as it's very difficult to debug on mobile browsers as you probably know, anyway, thanks for a great library, there was no way I was giving it up.

elbywan commented 2 months ago

Hey @MikeGriffinReborn, thanks for reporting the issue!

I'll replace the URL.canParse call with a good old try/catch block.