Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormData Object on IOS Safari sw worker #57

Closed
stebuklas opened this issue Jul 24, 2018 · 2 comments
Closed

FormData Object on IOS Safari sw worker #57

stebuklas opened this issue Jul 24, 2018 · 2 comments

Comments

@stebuklas
Copy link

stebuklas commented Jul 24, 2018

On IOS, service worker side, when using fetch and sending formData() it sends it as [FormData Object].

fetch(url, {
  method: 'POST',
  body: formData,
  credentials: "same-origin",
  headers: {
    'X-Requested-With':'XMLHttpRequest'
  }
})

When sending formData._blob, it send file, but there is more items appended to formData Object.

Any workaround?

@jimmywarting
Copy link
Owner

I don't know much of what's going on and can't pinpoint the problem in your or my code but i can give you some help to debug the problem.


The hole solution to this polyfill is that it's going to send a file in the end... and call formdata._blob() itself FormData.js#L376

Are you getting a references to native implementation or the patched fetch function when you console.log(fetch)?
the polyfill must be executed first to replace it...


I don't know why you get fewer items appended but you can inspect what is appended and what not by doing this:

var entries = formData.entries()
var iterator = entries.next()

while (!iterator.done) {
  console.log(iterator.value)
  entries.next()
}

Or with this:

// Logs the raw body:
new Response(formdata._blob()).text().then(console.log)

Calling formdata._blob() conditionally could potentially be a workaround:

fetch(url, {
  method: 'POST',
  body: formdata._blob ? formdata._blob() : formdata,
  credentials: "same-origin",
  headers: {
    'X-Requested-With':'XMLHttpRequest'
  }
})

Hopefully it should also set the requested content-type header to the correct value, hope we don't have the same problem as ie. (#44) - might be irrelevant

@jimmywarting
Copy link
Owner

closing b/c of no further discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants