Skip to content

Instantly share code, notes, and snippets.

@Klumper
Created January 13, 2021 09:11
Show Gist options
  • Save Klumper/d3e7f704f332dc29269a3601c4756881 to your computer and use it in GitHub Desktop.
Save Klumper/d3e7f704f332dc29269a3601c4756881 to your computer and use it in GitHub Desktop.
Trace current user's location with javascript fetch, using cloudflare.com/cdn-cgi/trace.
const cloudflareTrace = async () => {
try {
const response = await fetch('https://www.cloudflare.com/cdn-cgi/trace')
const rawData = await response.text();
const jsonData = Object.fromEntries(
rawData.trim()
.split('\n')
.map(line => line.split('='))
);
return jsonData;
} catch (error) {
console.error(`cloudflareTrace: ${error}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment