Last active
February 25, 2026 19:22
-
-
Save ikawka/6efa4551ca765d7d14e00e9a5ea539f8 to your computer and use it in GitHub Desktop.
Trace current user's location via javascript with CloudFlare provided the /cdn-cgi/trace is enabled.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($){ | |
| $(function(){ | |
| $.ajax({ | |
| contentType: 'application/text; charset=utf-8', | |
| crossBrowser: true, | |
| type: 'GET', | |
| url: '/cdn-cgi/trace', | |
| }).done(function(d){ | |
| var data = d.replace(/[\r\n]+/g, '","').replace(/\=+/g, '":"'); | |
| data = '{"' + data.slice(0, data.lastIndexOf('","')) + '"}'; | |
| var jsondata = $.parseJSON(data); | |
| console.log(jsondata.loc); | |
| }); | |
| }); | |
| })(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use https://cf-ns.com/cdn-cgi/trace in China