Is it Possible? - Addon for Firefox Mobil to allow zeroconf '.local' name resolution on android

He
today i tried to browse a embedded device website that is ‘discoverable’ by zeroconf/avahi.
from my ubuntu system this is working fine. i can use the devicename.local style to get to the website.
i then tried the same from my android phone firefox browser - only to get a ‘server not found’ response.
first i thought i have missed something - but after some internet-research i found that it seems the android system does not handle these zeroconf things by default…
(https://groups.google.com/forum/#!topic/groundcomputing/5MYwcvN8wWY)
Android has a API to scan for available services (and-or broadcast a own service) - but it seems this is not used/implemented in current browser.
The API can be found at https://developer.android.com/training/connect-devices-wirelessly/nsd.html

So my Idea was to create a Firefox-Mobile Addon that just does make this url-form available to use.

this would be my first addon - so not the easiest thing :wink: but there is some motivation to learn all things needed!
But i first want to know if you guys think this is possible at all.

i have had a first quick look at the WebExtension documentation and found a interesting locking part that could be useful for this:
webRequest and specially webRequest.RequestFilter
as filter/match url i successfully tested as described

<scheme>://<host><path>
*://*.local/
test:
var match = new MatchPattern("*://*.local/*");
var uri = BrowserUtils.makeURI("http://myhostname.local/");
match.matches(uri);
// results in true
var uri = BrowserUtils.makeURI("http://myhostname/");
match.matches(uri);
// results in false

If i understand this correct i can do something like this: (pseudo code)

register eventhandler for onBeforeRequest (with match filter for *.local url)
--> handle request:
    extract url zeroconf part
    lookup if zeroconf service with name is reachable
    rewrite url with direct ip
    register eventhandler for onHeadersReceived for this request
    --> handle headersReceived
        change ip back to zeroconf name

would this work?

  • that seems relative straight forward. only challenge would be to do the zeroconf discovery… (for this i don’t have searched yet… - but i think i can nott use the android build in api for this but would have to implement this myself in the extension.)

i hope you can give me some feedback on this idea.
sunny greetings stefan

additionally i have found some web-api targeting at services:
https://www.w3.org/TR/discovery-api/
it describes a draft for Network Service Discovery API
the first example from this document:

function showServices( services ) {
  // Show a list of all the services provided to the web page
  for(var i = 0, l = services.length; i < l; i++) console.log( services[i].name );
}

navigator.getNetworkServices('zeroconf:_boxee-jsonrpc._tcp').then(showServices);

have to check if something like this already exits in the WebExtension API - that would be a dream :wink:

Wow, that’s like not even really a sentence. Let’s try anyway:

the extension could add an eventlistener that listens on filterd request and if the filter matches [… and …] i know the target url/port and could modifie the request so it points to the target.

Yes. That you can do.

If the response comes back i also can modifie again the url so the users gets the requested url (and not the direkt ip)

I’m pretty sure there is no way to do that (in WebExtensions). Once you redirected that’s it. You cant modify anything else of the response than the headers.

only challenge would be to do the zeroconf discovery […] have to check if something like this already exits in the WebExtension API

No luck there. And I don’t think that any browser actually implemented navigator.getNetworkServices.

Thanks for your reply NilkasG.

sorrry iam not a native speaker and sometimes i don’t know how to pack the things i want to say…
i have edited my first post - so hopefully now its easier to read - you understand it correct…

hm - i thought i only have to modify the headers -

next weekend i will play/try with this request things to learn some more about this.

for the zeroconf discovery - yes that was what i found - the api reads simple and nice but no trace that a browser implements it…
have to research some more - what i found up till now is this:
chrome.mdns

Use the chrome.mdns API to discover services over mDNS.
This comprises a subset of the features of the NSD spec:
w3.org/TR/discovery-api/

node-mdns-js
could be a starting point how it can be done in javascript… have to check what are the requirements

firefox mobil had a bug with the mdns discovery - have to check what this really did…

mozilla flyweb project
some background info: https://hacks.mozilla.org/2016/09/flyweb-pure-web-cross-device-interaction/
–> currently uses mDNS over wifi
so it seems in someway there is code in the browser that can discover… hopefully it is some way usable by extensions

and if this is all to complex for me to build its a fun research on a interesting theme…

I wish you the best of luck. I think you will need it ^^
Have fun!