make a http trace request in javascript

To make an HTTP Trace request in JavaScript, you can use either the fetch() function or the XMLHttpRequest object.

Using fetch():

index.tsx
fetch(url, { method: 'TRACE'})
  .then(response => response.text())
  .then(data => console.log("Trace response:", data))
  .catch(error => console.error(error));
163 chars
5 lines

Using XMLHttpRequest:

index.tsx
const xhr = new XMLHttpRequest();
xhr.open('TRACE', url);
xhr.onload = function() {
  console.log("Trace response:", xhr.responseText);
};
xhr.onerror = function() {
  console.error(xhr.statusText);
};
xhr.send();
214 chars
10 lines

In both cases, make sure to replace url with the URL you want to Trace.

gistlibby LogSnag