Any way to get local IP address?

With WebExtensions, is there any way to get the local IP address of the device? Previously I was using nsIDNSService to do it with legacy addons.

AFAIK, not possible at the moment. The myIpAddress() was available in ProxyAutoConfig.cpp but it hasn’t been implemented due to being synchronous.

Do you want to get the local IP address in a WebExtension?
What would be the objective?

There is this one from @rob … but I get errors with it (RTCPeerConnection is not a constructor)

My code snippet does work (in tabs and popups, but not in background pages - due to the following bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1398083#c2). If you see the RTCPeerConnection is not a constructor error, then you have most likely disabled WebRTC.

I had not disabled it. I was testing it on Scratchpad.

@rob, interesting solution. I am postingyour answer here so future readers don’t have to find your reply in the stackoverflow post, which will probably get longer and longer as time goes by:

// Example (using the function below).
getLocalIPs(function(ips) { // <!-- ips is an array of local IP addresses.
    document.body.textContent = 'Local IP addresses:\n ' + ips.join('\n ');
});

function getLocalIPs(callback) {
    var ips = [];

    var RTCPeerConnection = window.RTCPeerConnection ||
        window.webkitRTCPeerConnection || window.mozRTCPeerConnection;

    var pc = new RTCPeerConnection({
        // Don't specify any stun/turn servers, otherwise you will
        // also find your public IP addresses.
        iceServers: []
    });
    // Add a media line, this is needed to activate candidate gathering.
    pc.createDataChannel('');
    
    // onicecandidate is triggered whenever a candidate has been found.
    pc.onicecandidate = function(e) {
        if (!e.candidate) { // Candidate gathering completed.
            pc.close();
            callback(ips);
            return;
        }
        var ip = /^candidate:.+ (\S+) \d+ typ/.exec(e.candidate.candidate)[1];
        if (ips.indexOf(ip) == -1) // avoid duplicate entries (tcp/udp)
            ips.push(ip);
    };
    pc.createOffer(function(sdp) {
        pc.setLocalDescription(sdp);
    }, function onerror() {});
}
<body style="white-space:pre"> IP addresses will be printed here... </body>