BUG: xhr object not functioning as expected

I’ve isolated the bug in this Vizhub: https://vizhub.com/Razpudding/85e6b27c38e643b39f3da07dd13ba97c?edit=files&file=index.js

For some reason this gives the error ‘Uncaught TypeError: xhr.addEventListener is not a function’

I was porting code from this codepen (https://codepen.io/Razpudding/pen/wNZoNQ) when I ran into the issue. The code runs fine there so this seems like a serious issue.

I’ve found the source of the issue. The xhr seems to be nested. I’ve written two versions in the aformentioned vizhub example. To my understanding the second should be working and I have no idea why the xhr is nested.

If you run the same code in the console you can see the second version which breaks in Vizhub is normally correct in the v8 engine.

Thanks for this! There is some magic going on in VizHub around XHR, to simulate fetching from the “local files”. It’s a little messy. The “fake” XHR tries to get the response from local files, and only when that fails does the “real” XHR get invoked. Intensive use of the XHR API may expose some missing pieces.

Details here https://github.com/datavis-tech/magic-sandbox/blob/master/src/magicSandbox.js#L124

Will investigate your cases.

So I realized the mocked XHR doesn’t have the addEventListener method. If you use onload it should work. The path forward here I think is to add an implementation for the addEventListener method.

Good to know. Thought I was going crazy for a second :sweat_smile:
I was going to keep using addEventListener with the workaround I wrote which basically gets the xhr out of its wrapped context, but then I realized that code wouldn’t work when used outside the sandbox.
So I think I will change it to onload and onerror as suggested.