WebReflection / linkedom

A triple-linked lists based DOM implementation.
https://webreflection.medium.com/linkedom-a-jsdom-alternative-53dd8f699311
ISC License
1.66k stars 80 forks source link

Error when using with axios: "TypeError: Cannot read properties of undefined (reading 'charAt')" #259

Open Jhon-Idrovo opened 7 months ago

Jhon-Idrovo commented 7 months ago

When used with axios I'm finding this error:

Screenshot 2024-03-03 at 1 50 27 PM

I did the work of following the stack trace and found where is the problem. At line 41 in https://github.com/axios/axios/blob/v1.x/lib/helpers/isURLSameOrigin.js

Screenshot 2024-03-03 at 1 56 47 PM

Seems like Axios checks if the browser is a "standard" one by creating an element. The problem is that it expects that when you create an anchor element it sets itself the pathname property when you add the href property.

I tried setting the user agent to msie or trident but the issue is still showing up

WebReflection commented 7 months ago

There won't be any userAgent sniffing ever in this module and the issue seems to be on HTMLAnchorElement not providing the whole standard API: https://github.com/WebReflection/linkedom/blob/main/esm/html/anchor-element.js

I think your issue is bigger than charAt as most of your urlParsing.xxx expectations are broken ... but there is a proper API in Web standards that is URL that doesn't need DOM at all to work ... I am not keen to consider patches that workaround anything at all that diverges on MSIE detection as that's a defunct browser and for good so, eventually, all I can think in here that could happen is that somebody files a PR that adds accessors (getters only) methods to that prototype that simply forward the result of new URL(this.href).prototcol or host or search or pathname and call it a day, as that's not even part of the rendering pipe so it's acceptable as bloat nobody asked, or needed, to date.

Are you that person that would file that PR? 😉