315

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?

2
  • 1
    I have found that Microsoft Edge Dev (based on Chromium) does not give me this error. Commented Sep 3, 2019 at 20:36
  • 1
    Did you try checking in Firefox ? Commented Jul 29, 2020 at 8:19

18 Answers 18

373

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.

24
  • 418
    Not being able to see response data almost entirely kills the point of "preserve log"!
    – Alkanshel
    Commented Jul 25, 2017 at 19:31
  • 51
    No, in Chrome 61, it can definitely also happen if "Preserve log" is not checked, and without leaving the page. Commented Sep 20, 2017 at 13:58
  • 14
    Still experiencing this issue with chrome 73.0, the onunload fix doesn't work for me for some reason.
    – Onza
    Commented Mar 18, 2019 at 12:07
  • 18
    window.onunload = function() { debugger; } doesn't work anymore Commented Mar 30, 2020 at 10:43
  • 15
    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.
    – Alex Grin
    Commented Feb 9, 2021 at 9:44
99

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.

5
  • 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
    Commented Jul 25, 2018 at 15:37
  • 23
    Chrome also doesn't have Firefox's convenient "edit and resend" request option.
    – Antimony
    Commented Jul 25, 2018 at 18:02
  • 1
    Yes... Also used FF to get the thing done... Worked as expected. We're living treacherous times!
    – nmirceac
    Commented Jan 30, 2020 at 7: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 Commented Jan 31, 2020 at 8: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
    Commented Mar 4, 2020 at 10:12
75

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.

10
  • 41
    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
    Commented Apr 22, 2018 at 1:34
  • 6
    Is this limit configurable in any way? Commented May 10, 2018 at 9: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
    Commented Oct 9, 2018 at 21:45
  • 1
    I'm seeing the issue for 6MB JSON :(
    – Lee Gunn
    Commented Apr 27, 2020 at 16:10
  • 1
    Also hitting this on JSON response arond 6mb uncompressed. Commented Jun 4, 2020 at 15:22
41

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

3
  • What's the advantage of the Source tab over window.onunload = function() { debugger; }? Commented Sep 22, 2018 at 21:01
  • 2
    you don't need to write the code for the debugger, and you can debug on higher environments where you maybe jumping between pages and don't preserve the same window Commented Mar 26, 2019 at 18:35
  • 2
    window.onunload = function() { debugger; } didn't work for me, this did. thanks! Commented Apr 10, 2019 at 9:00
38

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())
10
  • 3
    Is there any bug opened about this behaviour of dev tools? This is ridiculous
    – user555121
    Commented Mar 30, 2021 at 15:41
  • 1
    @Kos agree, still not fixed. Just spent 1:30 hour figuring out why I didn't get a response.
    – Tim
    Commented Jul 5, 2021 at 14:57
  • 3
    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
    Commented Aug 24, 2021 at 4:58
  • 1
    Thanks a lot, I wouldn't guess such behavior in a million years. Btw. I'm using Edge Dev 96.
    – mikiqex
    Commented Oct 11, 2021 at 10:25
  • 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
    Commented Jun 29, 2022 at 15:27
18

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

2
  • 7
    chrome is still broken for not showing the response (in any shape whatsoever) - FF worked for me
    – nmirceac
    Commented Jan 30, 2020 at 7:41
  • 1
    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
    Commented May 15, 2020 at 4:01
6

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

1
  • 1
    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
    Commented Jan 18, 2023 at 9:49
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.

1
  • 2
    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 :/ Commented Jun 16, 2020 at 9: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.');
1
  • 2
    well, that's because you aren't sending anything back to the client...?
    – Scar
    Commented Jul 27, 2022 at 20:15
1

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!

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

0

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

0

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

It will give response for sure.

2
  • Isn't that super inconvenient to switch between browser, ide and postman? Commented May 18, 2021 at 2:21
  • @BhargavNanekalva, Agreed but it helps sometimes. Commented Nov 15, 2021 at 6:52
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.sstatic.net/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.

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

0

One possibility, when project assembly (dll) is renamed, latest global.asax is not copied in iis webserver. (global.asax has refrence to new assembly in inherits section)

0

I discovered that the response body and preview are hidden if there's a file attached in the request body:

fetch("https://httpbin.org/post?with-file=1", {
    method: "post",
    body: document.querySelector("input").files[0],
});

You'll see this error:

Failed to load response data: Request content was evicted from inspector cache

DevTools Network tab displaying the error

But if you don't attach anything in the request, it works as expected:

fetch("https://httpbin.org/post?empty=1", {
    method: "post",
});

DevTools Network tab displaying the response data

I've made an issue report in Chromium. You can check it for more details.

-1

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

1
  • Good to know, but this isn't answering the question
    – Gabriel
    Commented Dec 2, 2022 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.