289

Why does my Chrome developer tools show

Failed to show response data

in response when the content returned is of type text/html?

What is the alternative to see the returned response in developer tools?

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
randominstanceOfLivingThing
  • 16,873
  • 13
  • 49
  • 72

16 Answers16

357

I think this only happens when you have 'Preserve log' checked and you are trying to view the response data of a previous request after you have navigated away.

For example, I viewed the Response to loading this Stack Overflow question. You can see it.

Response Data

The second time, I reloaded this page but didn't look at the Headers or Response. I navigated to a different website. Now when I look at the response, it shows 'Failed to load response data'.

No Response Data

This is a known issue, that's been around for a while, and debated a lot.

pegasus
  • 21
  • 6
Gideon Pyzer
  • 22,610
  • 7
  • 62
  • 68
  • 387
    Not being able to see response data almost entirely kills the point of "preserve log"! – Alkanshel Jul 25 '17 at 19:31
  • 49
    No, in Chrome 61, it can definitely also happen if "Preserve log" is *not* checked, and without leaving the page. – O. R. Mapper Sep 20 '17 at 13:58
  • The response data can be large, and with preserve log checked indefinitely, would build up significantly hindering DevTool performance. To discard the response data upon navigation was probably done by design. If you have some suggestions, comment on the thread linked above. – Gideon Pyzer Oct 30 '17 at 08:39
  • It does not work if request you want to inspect gives immediate redirect with javascript. There is just no time to open console and add onunload handler. But Firefox helps in such situations. – cronfy Jan 26 '18 at 08:01
  • As alternative you may try https://chrome.google.com/webstore/detail/network-record/ihbkogfblhfbnompooimhejpkidoipcl extension – ievgen Mar 15 '18 at 09:11
  • 14
    Still experiencing this issue with chrome 73.0, the `onunload` fix doesn't work for me for some reason. – Onza Mar 18 '19 at 12:07
  • Same here: the unload fix pasted into the console did not work in my case, but @Nolan's advice with the Sources tab did (it also seemed more elegant). – ᴍᴇʜᴏᴠ Apr 10 '19 at 09:02
  • @GideonPyzer sorry, can the workaround debug live code? – Vincent Aug 19 '19 at 08:58
  • 1
    the error happens also when i do not have "Preserve log" checked – Andrei Diaconescu Feb 19 '20 at 17:58
  • Your solution seems promising, but it clearly skips some steps for someone with less knowledge than you do about chrome. What is one supposed to do with "window.onunload = function() { debugger; }"? – Kevin S. Mar 19 '20 at 21:50
  • 17
    `window.onunload = function() { debugger; }` doesn't work anymore – van_folmert Mar 30 '20 at 10:43
  • 3
    You cannot comment on the thread linked unless you have editor permission, I tried. And adding debugger to the source is a no go as this is production level code, debug code is not an option. And Firefox apperently can preserve it fine, even a few hours of log, so whats chromes problem? Yes it might eat memory, but only if you open devtools, and then you are probably more interested in data than in performance. And if its still a problem, add a toggle. – David Mårtensson Jun 16 '20 at 09:39
  • Unbelievable. 8 year bug?! At the VERY least, the window should show a warning about the missing data. – rinogo Nov 10 '20 at 03:13
  • GAAAAAH This bit me AGAIN. A few hours down the drain. – rinogo Feb 03 '21 at 18:16
  • 13
    This beforeunload handler didn't work for me, but its slightly modified version worked: `window.addEventListener('beforeunload', function(e) { e.returnValue = 'Are you sure?'; return e.returnValue; });` Just click "Cancel" in the confirmation modal to prevent page reload, and go to the Network tab to see the response body - it is there. – Alexey Grinko Feb 09 '21 at 09:44
  • 3
    I advice everybody who face this issue to star it here: https://bugs.chromium.org/p/chromium/issues/detail?id=141129 It is still not fixed because it has to little stars :( – user1439838 Jun 04 '21 at 10:18
  • 7
    As much as I respect highly skilled developers of Chrome, I do think they are on drugs or have some other mental issues. Having a Dev Tools feature that IS able to store request history but not request details is Very strange, not fixing this bug/feature it 9 years is outright weird. – Alex Nov 05 '21 at 04:11
  • @user1439838 how to incr stars? – sammy Dec 29 '21 at 06:30
  • @user1439838 how to star it? – Revadike May 23 '22 at 00:20
  • Sorry, I am getting this error with Preserve logs, on a query requested on the current page, I am getting no output from "Response" tab but when I open page in other tab, I am getting the output. When I'am debbuging code, the output seems ok. – Loenix Jan 18 '23 at 09:37
  • @Revadike The star button is in the top left just before it says "Starred by 300 users". – David Klempfner May 03 '23 at 02:45
88

As described by Gideon, this is a known issue with Chrome that has been open for more than 5 years with no apparent interest in fixing it.

Unfortunately, in my case, the window.onunload = function() { debugger; } workaround didn't work either. So far the best workaround I've found is to use Firefox, which does display response data even after a navigation. The Firefox devtools also have a lot of nice features missing in Chrome, such as syntax highlighting the response data if it is html and automatically parsing it if it is JSON.

Top-Master
  • 7,611
  • 5
  • 39
  • 71
Antimony
  • 37,781
  • 10
  • 100
  • 107
  • 10
    Wow, great thing. Needing to debug an error which only occurs to Chrome, not Firefox. So also no option for me. Seriously, why does everyone say the Chrome web tools are so much better than Firefox's? Seems like they didn't try Firefox for years. – mozzbozz Jul 25 '18 at 15:37
  • 22
    Chrome also doesn't have Firefox's convenient "edit and resend" request option. – Antimony Jul 25 '18 at 18:02
  • 1
    Yes... Also used FF to get the thing done... Worked as expected. We're living treacherous times! – nmirceac Jan 30 '20 at 07:42
  • @Antimony chrome did had "Resend" option for quite a while, but in one of the last releases they have removed even that... Luckily one can do quick `fetch(...copied link...)` in console, and observe response in network tab – Ivan Hušnjak Jan 31 '20 at 08:51
  • 1
    Still getting this even now. For crying out loud I'd rather them fix what they already have rather than introduce pointless features like eager evaluation in the console and neglect the quality of their fundamental developer tools. – thephpdev Mar 04 '20 at 10:12
72

For the ones who are getting the error while requesting JSON data:

If your are requesting JSON data, the JSON might be too large and that what cause the error to happen.

My solution is to copy the request link to new tab (get request from browser) copy the data to JSON viewer online where you have auto parsing and work on it there.

Tomz
  • 771
  • 5
  • 6
  • 38
    not really a solution though. I work with authentication and such. Defies the purpose of the dev tools. Somebody should probably create some bugreport somewhere. Correct answer here though – phil294 Apr 22 '18 at 01:34
  • 6
    Is this limit configurable in any way? – Willem Hengeveld May 10 '18 at 09:39
  • In my case it happened at 23MB which is a stupid large JSON response.... I opened an issue to have the error message made more descriptive. – boatcoder Oct 09 '18 at 21:45
  • 1
    I'm seeing the issue for 6MB JSON :( – Lee Gunn Apr 27 '20 at 16:10
  • 1
    Also hitting this on JSON response arond 6mb uncompressed. – miki noidea Jun 04 '20 at 15:22
  • I got the error with only 227KB of json - scaled it back and it works ok for 25KB, so definitely a size issue – mgraham Jan 07 '21 at 14:53
  • I got this when the site just wasn't running (local development out of Visual Studio) – xr280xr Mar 18 '21 at 03:51
  • I was able to get at the data in a roundabout way by right clicking the request, choosing Copy > PowerShell request, storing the result as `$Response` in PowerShell, then following the example [here](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-7.1#example-4--writes-the-response-content-to-a-file-using-the-encoding-defined-in-the-requested-page-) to stream it to a file. (May have to decode if you're requesting a compressed response.) – Isaac Lyman Aug 27 '21 at 17:36
  • Unable to view the response of 16MB – Akshat Zala Jul 22 '22 at 03:42
  • this will only get the current value of the response, which might have changed from the time when the original call had happened. – Aathreya Jun 30 '23 at 10:11
38

As described by Gideon, this is a known issue.
For use window.onunload = function() { debugger; } instead.
But you can add a breakpoint in Source tab, then can solve your problem. like this: enter image description here

Fitz
  • 449
  • 4
  • 5
35

If you make an AJAX request with fetch, the response isn't shown unless it's read with .text(), .json(), etc.

If you just do:

 r = fetch("/some-path");

the response won't be shown in dev tools.
It shows up after you run:

r.then(r => r.text())
gre_gor
  • 6,669
  • 9
  • 47
  • 52
  • 3
    Is there any bug opened about this behaviour of dev tools? This is ridiculous – Kos Mar 30 '21 at 15:41
  • 1
    @Kos agree, still not fixed. Just spent 1:30 hour figuring out why I didn't get a response. – Tim Jul 05 '21 at 14:57
  • 1
    Just wasted an hour on this, looks like Chrome is still not fixed. I finally checked with Postman because I tought I was going crazy and there was my content in all its glory. – Stefan Aug 24 '21 at 04:58
  • Same here. I use Brave but was reproducible on Chrome too (obviously). Bug not present in Safari. Just lost two hours on this, assumed there was a problem with the server. – developius Sep 09 '21 at 03:53
  • 1
    Thanks a lot, I wouldn't guess such behavior in a million years. Btw. I'm using Edge Dev 96. – mikiqex Oct 11 '21 at 10:25
  • This answer should be accepted. Tried so many things and to finally find out this. Duh! – mani bharataraju Jun 29 '22 at 15:12
  • 1
    @manibharataraju The question itself is quite vague. There are many reasons and solutions for this problem and the accepted one is the one that helped the asker. – gre_gor Jun 29 '22 at 15:27
  • @manibharataraju Also now I can't reproduce this problem. The content is shown without reading it first. It seems this "bug" was fixed. – gre_gor Jun 29 '22 at 15:31
  • @gre_gor if the question is vague we don't like wild guesses. Please report or ask for an edit. – amac Aug 23 '22 at 23:35
  • that was the right answer for me – Gabriel Sep 30 '22 at 08:51
19

"Failed to show response data" can also happen if you are doing crossdomain requests and the remote host is not properly handling the CORS headers. Check your js console for errors.

deweydb
  • 2,238
  • 2
  • 30
  • 37
  • 7
    chrome is still broken for not showing the response (in any shape whatsoever) - FF worked for me – nmirceac Jan 30 '20 at 07:41
  • You are right! But this is exactly why I need the reponse to understand why my request is failing. Everything works fine with curl, but chrome still fails with "Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource" – Amir May 15 '20 at 04:01
3

For the once who receive this error while requesting large JSON data it is, as mentioned by Blauhirn, not a solution to just open the request in new tab if you are using authentication headers and suchlike.

Forturnatly chrome does have other options such as Copy -> Copy as curl. Running this call from the commandoline through cURL will be a exact replicate of the original call.

I added > ~/result.json to the last part of the commando to save the result to a file. Otherwise it will be outputted to the console.

thephper
  • 2,342
  • 22
  • 21
  • 1
    An exact replica is no use if the server state supplying the response has changed. So for me, that have to wait around 40 minutes for an event to happen, and that event triggers a new page, this completely breaks the whole use. It should be an option that could be toggled. UInfortunatly there is no vote or comment option for common visitors to the issue listed in a previous comment unless you are part of their team :/ – David Mårtensson Jun 16 '20 at 09:34
3

For those coming here from Google, and for whom the previous answers do not solve the mystery...

If you use XHR to make a server call, but do not return a response, this error will occur.

Example (from Nodejs/React but could equally be js/php):

App.tsx

const handleClickEvent = () => {
    fetch('/routeInAppjs?someVar=someValue&nutherVar=summat_else', {
        method: 'GET',
        mode: 'same-origin',
        credentials: 'include',
        headers: {
          'content-type': 'application/json',
          dataType: 'json',
        },
    }).then((response) => {
        console.log(response)
    });
}

App.js

app.route('/getAllPublicDatasheets').get(async function (req, res) {
    const { someVar, nutherVar } = req.query;
    console.log('Ending here without a return...')
});

Console.log will here report:

Failed to show response data

To fix, add the return response to bottom of your route (server-side):

res.json('Adding this below the console.log in App.js route will solve it.');
cssyphus
  • 37,875
  • 18
  • 96
  • 111
3

As long as the body of the Response is not consumed within your code (using .json() or .text() for instance), it won't be displayed in the preview tab of Chrome dev tools

Gabriel
  • 3,633
  • 1
  • 23
  • 13
  • You are right, if the body is not consumed, chrome is not displaying anything in Response and Preview tabs. Take care that json() and text() are returning a Promise. – Loenix Jan 18 '23 at 09:49
0

Bug still active. This happens when JS becomes the initiator for new page(200), or redirect(301/302) 1 possible way to fix it - it disable JavaScript on request. I.e. in puppeteer you can use: page.setJavaScriptEnabled(false) while intercepting request(page.on('request'))

RomanAvr
  • 101
  • 2
0

another possibility is that the server does not handle the OPTIONS request.

echo
  • 2,666
  • 1
  • 25
  • 17
0

One workaround is to use Postman with same request url, headers and payload.

It will give response for sure.

Yuvraj Patil
  • 7,944
  • 5
  • 56
  • 56
0

For me, the issue happens when the returned JSON file is too large.

If you just want to see the response, you can get it with the help of Postman. See the steps below:

  1. Copy the request with all information(including URL, header, token, etc) from chrome debugger through Chrome Developer Tools->Network Tab->find the request->right click on it->Copy->Copy as cURL.
  2. Open postman, import->Rawtext, paste the content. Postman will recreate the same request. Then run the request you should see the JSON response. [Import cURL in postmain][1]: https://i.stack.imgur.com/dL9Qo.png

If you want to reduce the size of the API response, maybe you can return fewer fields in the response. For mongoose, you can easily do this by providing a field name list when calling the find() method. For exmaple, convert the method from:

const users = await User.find().lean();

To:

const users = await User.find({}, '_id username email role timecreated').lean();

In my case, there is field called description, which is a large string. After removing it from the field list, the response size is reduced from 6.6 MB to 404 KB.

Rong Zhuang
  • 121
  • 1
  • 3
0

I had the same problem and none of the answers worked, finally i noticed i had made a huge mistake and had chosen other as you can see
enter image description here

Now this seems like a dumb mistake but the thing is even after removing and reinstalling chrome the problem had remained (settings are not uninstalled by default when removing chrome) and so it took me a while until I found this and choose All again...! This happened because my backend doesn't handle OPTIONS method and because I had clicked on other by mistake which caused me to spend a couple days trying answers!

Ali Ahmadi
  • 93
  • 1
  • 3
  • 12
0

In my case, when sending post data with fetch, make sure you use the option to enable cors and then define cors on the remote origin.


fetch('', {
    mode: 'cors',//enable cors
    method: 'post',
    body: formData,//don't forget to stringify if server accepts json
    headers: {
        'content-Type': 'application/json' //remove if server accepts form-data
    }
})

Then, if you are using a local development environment, you can configure Cors to accept requests from all domains

const express = require('express');
const cors = require('cors');
const app = express();

app.use(cors()); // Enable CORS for all domains

I hope this helps someone

-2

Use firefox, it always display the response and give the same tools that chrome does.

JohnnyE
  • 1
  • 1