Skip to content

Instantly share code, notes, and snippets.

@andresgcarmona
Created October 19, 2022 20:05
Show Gist options
  • Save andresgcarmona/3d765fb059c030785561ce5b3177f3a9 to your computer and use it in GitHub Desktop.
Save andresgcarmona/3d765fb059c030785561ce5b3177f3a9 to your computer and use it in GitHub Desktop.
Show page headers.
// showheaders.js
// https://github.com/bgrins/devtools-snippets
// Print out response headers for current URL.
(function() {
var request=new XMLHttpRequest();
request.open('HEAD',window.location,true);
request.onload = request.onerror = function () {
var headers = request.getAllResponseHeaders();
var tab = headers.split("\n").map(function(h) {
return { "Key": h.split(": ")[0], "Value": h.split(": ")[1] }
}).filter(function(h) { return h.Value !== undefined; });
console.group("Request Headers");
console.log(headers);
console.table(tab);
console.groupEnd("Request Headers");
};
request.send(null);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment