Developer Tools - fetch POST requests not show in Network tab
Categories
(DevTools :: Netmonitor, defect, P3)
Tracking
(Not tracked)
People
(Reporter: betsy.gamrat, Assigned: sakshaat.dc, Mentored)
Details
(Keywords: good-first-bug)
Attachments
(4 files)
Updated•7 years ago
|
Comment 1•7 years ago
|
||
(In reply to betsy.gamrat from comment #0)
Executed this code:
return new Promise((resolve) => { fetch('/api/asset_statuses.json', {'method': 'POST', 'body': JSON.stringify(state.items), 'headers': 'Content-Type: application/json;charset=utf-8'})
.then(res => res.json())
.then(res => {
alert('ha');
console.log(res);
resolve();
})
})Quick test - paste this in the web console tab -
new Promise((resolve) => { fetch('/api/asset_statuses.json', {'method':
'POST', 'body': {"i":"j"}, 'headers': 'Content-Type: application/json;
charset=utf-8'}) .then(res => res.json()) .then(res => { alert('ha');
console.log(res); resolve(); }) })
I am getting an error when executing these examples:
TypeError: 'headers' member of RequestInit could not be converted to any of: Headers, ByteStringSequenceSequence, ByteStringByteStringRecord.
That error blocks the XHR from actual excution.
Do you see that?
Is this the issue?
Honza
| Reporter | ||
Comment 2•7 years ago
|
||
Console tab entry and result - Firefox Developer Edition ("Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0")
Same results occur with Firefox Quantum ("Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:64.0) Gecko/20100101 Firefox/64.0")
| Reporter | ||
Comment 3•7 years ago
|
||
Network tab display (same for both Firefox Quantum and Firefox Developer Edition)
Comment 4•7 years ago
|
||
I did fix the way how headers how passed into fetch (it should be an object not string in 66) and I a now able to execute it.
My Example looks as follows:
new Promise((resolve) => {
fetch("/api/asset_statuses.json", {
method: "POST",
body: {"i": "j"},
headers: {
"Content-Type": "application/json;"
},
}).then(res => {
alert("ha");
console.log(res);
resolve();
});
})
I can see the request in the Console (see the screenshot) as well as in the Network monitor panel.
Can you try my version on your machine?
Does it work for you?
Honza
Comment 5•7 years ago
|
||
Note that in order to see the XHR requests in the Console you need to check the XHR filter
Honza
| Reporter | ||
Comment 6•7 years ago
|
||
Request is shown but Params not readable
Comment 7•7 years ago
|
||
Thanks for the update, I can see the problem now!
New STR:
- Open DevTools Toolbox on any page (e.g. google.com)
- Select the Network panel (so the monitoring is activated) and consequently go to the Console panel
- Execute the following script in the Console panel:
new Promise((resolve) => {
fetch("/api/asset_statuses.json", {
method: "POST",
body: {"i": "j"},
headers: {
"Content-Type": "application/json;"
},
}).then(res => {
alert("ha");
console.log(res);
resolve();
});
})
- Go the Network panel and click on the request
- Check out the Params tab. It shows
[object Object]instead of posted JSON -> BUG
See this screenshot: https://bugzilla.mozilla.org/attachment.cgi?id=9037709
Honza
Comment 8•7 years ago
|
||
A link for anyone interested in fixing this bug:
This is the place where the Param side panel is rendered and the bug could be somewhere around:
https://searchfox.org/mozilla-central/rev/c035ee7d3a5cd6913e7143e1bce549ffb4a566ff/devtools/client/netmonitor/src/components/ParamsPanel.js#132
Honza
| Assignee | ||
Comment 9•7 years ago
|
||
Hi Jan, I am new to contributing to Mozilla's codebase. Would it be okay if I give this bug a shot?
Comment 10•7 years ago
|
||
Sure, thanks!
Honza
Comment 11•6 years ago
|
||
Hi Sakshaat
Are you still working on this? Do you require assistance? :)
Comment 12•6 years ago
|
||
Hi Honza
So I read up on the proper syntax use fetch to POST JSON data here.
The correct syntax should then be (the only change is that we JSON.stringify the object to pass in the body):
new Promise((resolve) => {
fetch("/api/asset_statuses.json", {
method: "POST",
body: JSON.stringify({"i": "j"}),
headers: {
"Content-Type": "application/json;"
},
}).then(res => {
alert("ha");
console.log(res);
resolve();
});
})
Is this still a valid bug then? Or should we display a message saying something like "Params cannot be parsed" in the Params Panel?
Comment 13•6 years ago
|
||
Official documentation on proper syntax here:
body: Any body that you want to add to your request: this can be a Blob, BufferSource, FormData, URLSearchParams, or USVString object. Note that a request using the GET or HEAD method cannot have a body.
Comment 14•6 years ago
|
||
(In reply to Heng Yeow (:tanhengyeow) from comment #12)
Is this still a valid bug then? Or should we display a message saying something like "Params cannot be parsed" in the Params Panel?
Good point. I think we can close (I also checked with Chrome DevTools and it works the same way)
Thanks!
Honza
| Assignee | ||
Comment 15•6 years ago
|
||
Sorry about that, I couldn't get to it early enough, but it seems to be resolved so that's great.
Description
•