Closed Bug 1514537 Opened 7 years ago Closed 6 years ago

Developer Tools - fetch POST requests not show in Network tab

Categories

(DevTools :: Netmonitor, defect, P3)

65 Branch
defect

Tracking

(Not tracked)

RESOLVED WONTFIX

People

(Reporter: betsy.gamrat, Assigned: sakshaat.dc, Mentored)

Details

(Keywords: good-first-bug)

Attachments

(4 files)

User Agent: Mozilla/5.0 (X11; Linux x86_64; rv:65.0) Gecko/20100101 Firefox/65.0 Steps to reproduce: 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(); }) }) Was hoping to use the Network tab to look at the response, but the request is not displayed in the Network tab. 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(); }) }) Then paste this - var xhr = new XMLHttpRequest(); xhr.open("POST", '/api/asset_statuses.json', true); //Send the proper header information along with the request xhr.setRequestHeader("Content-Type", "application/json"); xhr.onreadystatechange = function () { // Call a function when the state changes. if (this.readyState === XMLHttpRequest.DONE && this.status === 200) { // Request finished. Do processing here. } } xhr.send('{"i":"j"}'); Firefox Developer Edition - 65.0b4 (64-bit) - Ubuntu 18.04 Also occurs with Firefox 64.0 (64-bit) Actual results: Nothing65.0b4 (64-bit) Expected results: I was expecting to see the request and response in the Network tab of the Developer Tools
Component: General → Netmonitor
Product: Core → DevTools

(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

Flags: needinfo?(betsy.gamrat)
Attached image console-tab.png

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")

Flags: needinfo?(betsy.gamrat)
Attached image network-tab.png

Network tab display (same for both Firefox Quantum and Firefox Developer Edition)

Attached image image.png

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

Flags: needinfo?(betsy.gamrat)

Note that in order to see the XHR requests in the Console you need to check the XHR filter
Honza

Attached image network tab 2.png

Request is shown but Params not readable

Flags: needinfo?(betsy.gamrat)

Thanks for the update, I can see the problem now!

New STR:

  1. Open DevTools Toolbox on any page (e.g. google.com)
  2. Select the Network panel (so the monitoring is activated) and consequently go to the Console panel
  3. 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();
  });
})
  1. Go the Network panel and click on the request
  2. 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

Mentor: odvarko
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: good-first-bug
Priority: -- → P3

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

Hi Jan, I am new to contributing to Mozilla's codebase. Would it be okay if I give this bug a shot?

Flags: needinfo?(odvarko)

Sure, thanks!
Honza

Assignee: nobody → sakshaat.dc
Status: NEW → ASSIGNED
Flags: needinfo?(odvarko)

Hi Sakshaat

Are you still working on this? Do you require assistance? :)

Flags: needinfo?(sakshaat.dc)

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?

Flags: needinfo?(odvarko)

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.

(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

Status: ASSIGNED → RESOLVED
Closed: 6 years ago
Flags: needinfo?(odvarko)
Resolution: --- → WONTFIX

Sorry about that, I couldn't get to it early enough, but it seems to be resolved so that's great.

Flags: needinfo?(sakshaat.dc)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: