jpillora / xdomain

A pure JavaScript CORS alternative
https://jpillora.com/xdomain/
3.12k stars 270 forks source link

Global Namespace Pollution #224

Open kpnielsen opened 1 year ago

kpnielsen commented 1 year ago

xdomain pollutes the global namespace. In particular, it overrides window.FormData. This can break sites on which other scripts use FormData in fetch calls to submit forms via AJAX. To be more precise, consider the following call:

const myForm = document.getElementById('myForm')
myForm.addEventListener('submit', evt => {
  evt.preventDefault()

  fetch(form.dataset.ajaxUri, {
    method: 'POST',
    body: new FormData(form)
  }).then(result => {
    // do something with the result
  })
})

The payload of that request sent when submitting the form will not be the actual form data, but [object Object].