Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get IP and Location from the browser js
function getCloudflareJSON(data): Promise<{
fl: string
h: string
ip: string
ts: number
visit_scheme: string
uag: string
colo: string
http: string
loc: string
tls: string
sni: string
warp: string
gateway: string
}> {
return fetch("https://1.1.1.1/cdn-cgi/trace")
.then(res => res.text())
.then(data => {
const arr = data
.trim()
.split("\n")
.map(e => e.split("="))
return Object.fromEntries(arr)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment