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 is missing when submit by fetch #64

Closed
spacedragon opened this issue Apr 18, 2017 · 9 comments
Closed

Formdata is missing when submit by fetch #64

spacedragon opened this issue Apr 18, 2017 · 9 comments
Assignees

Comments

@spacedragon
Copy link

spacedragon commented Apr 18, 2017

My following code failed

 const data = new FormData();
    data.append('username', username);
    data.append('password', password);
    fetch(`authenticate/`, {
      method: 'POST',
      credentials: 'same-origin',
      body: data
    })

should code here https://github.com/jpillora/xhook/blob/gh-pages/src/xhook.coffee#L511
handle formdata ?

@spacedragon spacedragon changed the title formdata missing when submit by fetch Formdata missing when submit by fetch Apr 18, 2017
@spacedragon spacedragon changed the title Formdata missing when submit by fetch Formdata is missing when submit by fetch Apr 18, 2017
@spacedragon
Copy link
Author

close since nobody care.

@morsdyce
Copy link
Collaborator

Hi @spacedragon,
There is no reason to get upset, you have to remember that we are people who are working on open source on our free time and don't always have time to reply because of "life".

I have just came back from a 1 month vacation, where I had no access to a computer so it's really not that we don't care about your issue but we might be just busy.

Now let's talk about the issue, you say that form data is missing from fetch, how do you know it's missing? Did you check it on the request or in the chrome dev tools?

Can you post a small example where this isn't working or post more data on how you tested it and which hooks and operations in those hooks you used so we can further debug it?

Please note that if you found out the form data is missing using the Chrome devtools, it is a bug in Google Chrome which I opened an issue for and should be fixed hopefully in the near future.

Here is the bug report if you wish to track it and see when it's fixed:
https://bugs.chromium.org/p/chromium/issues/detail?id=698209

Thanks for reporting the bug and helping us improve!

@morsdyce morsdyce reopened this May 15, 2017
@morsdyce
Copy link
Collaborator

morsdyce commented Aug 1, 2017

Hi @spacedragon

Unfortunately I'm not able to reproduce this issue so unless you can provide more info or a failing examples I'll have to close this issue.

Please let me know if this is still relevant so we can try to resolve this issue.

Thanks

@spacedragon
Copy link
Author

spacedragon commented Aug 2, 2017

try the following code;

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>

<form>
  <input type="text" id="username" name="username">
  <input type="password" id="password" name="password">
  <button id="submit" type="button">submit</button>
</form>

<pre id="two"></pre>

<!--<script src="./xhook.js"></script>-->
<script type="text/javascript">
  /*xhook.after(function (request, response) {
    console.log(request, response)
  });*/

  document.getElementById("submit").addEventListener("click", function () {
    var username = document.getElementById("username").value;
    var password = document.getElementById("password").value;
    const data = new FormData();
    data.append('username', username);
    data.append('password', password);
    console.log("submitting data,", data);
    fetch(`authenticate/`, {
      method: 'POST',
      credentials: 'same-origin',
      body: data
    });
  });


</script>
</body>
</html>
  1. without use xhook (we have payload)
    image

  2. enable xhook
    image

  3. I don't think it's relevant to chrome dev tools, since we found this problem because of our servers can't receive any valid request.

@morsdyce
Copy link
Collaborator

morsdyce commented Aug 2, 2017

Ok, I am able to reproduce the issue. It looks like the request parameters turn in [Object object] instead of the correct payload.

I do want to mention though that testing this using the chrome dev tools currently isn't possible because of the bug I mentioned which was confirmed by the chromium team.

I reproduced the issue with Firefox and will start looking into it

@morsdyce
Copy link
Collaborator

morsdyce commented Aug 2, 2017

Hi @spacedragon

The problem was that the fetch implementation wasn't sending the real FormData object to the server causing the server to recieve a string of "[Object object]".
This is now fixed along with a new test case that checks this functionality keeps working.

Will appreciate if you could try it out and see if it fixed your version by installing xhook with the latest commit hash: 93879b7

If you are using npm it should look like this in your package.json:

{
  "dependencies": {
    "xhook": "jpillora/xhook#93879b7"
  }
}

@morsdyce morsdyce reopened this Aug 2, 2017
@morsdyce
Copy link
Collaborator

Fixed in 1.4.5

@Mingling94
Copy link

Mingling94 commented Apr 17, 2020

I'm finding this issue when using 1.4.5 and 1.4.9. It may be an environmental thing or something specific to my package code, but it's the same symptom of the body FormData getting wiped out and showing [Object object] instead. It's odd that I would find this issue in later revisions. I've confirmed that the xhook node_module folder I have is actually built with 1.4.9 and contains code from 93879b7

The weirdest part is that this is happening for me despite using the native window fetch by capturing it from xhook.fetch

@Mingling94
Copy link

Mingling94 commented Apr 29, 2020

Just verifying, I'm still encountering this.

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

3 participants