Search code examples
javascripthtmlgoogle-chrome-extensionip-addressbrowser-extension

JavaScript to get Client IP Address bypassing Browser Extensions


I am using an external API and part of the parameter of the API is an IP address. I looked up how to do it and I used the ipify version in this answer because it has no limitations. Here is the script:

$.getJSON('https://api.ipify.org?format=jsonp&callback=?', function(data) {
  console.log(data); 
  console.log(data.ip.toString()); 

  retrieved_entity_ip = data.ip.toString();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

It's working so well until some clients were being shown errors and according to the logs it was because their IP address was missing. I narrowed it down to their browser extension, uBlock Origin, which was preventing the script from running.

Is there a more reliable way to do this without having to do any upgrade to paid tiers?


Solution

  • You can use public services which are not blacklisted by ad blockers, like https://www.myexternalip.com/json but eventually it can also be blacklisted, it's not under your control.

    The most reliable way to reduce the risk of using a service that can be blacklisted would be building your own server as suggested in descriptions or keeping an updated list of alternative services in case of failed requests. Probably you won't get rid of your "problem" without spending some money.