Following to the last post about wsreload, I will now explain how I implemented the reload mechanism.
Most existing browser reloaders use dirty X hacks like
xvkbd to send the
[F5] key to the browser window. This doesn’t work reliably. No really. There’s also other solutions, like launching your browser with a debug backdoor (
--remote-shell-port) but it kinda mess up everything else.
So to avoid these dirty hacks wsreload ships with a browser extension which role is to tell the browser to reload the page directly from the extension API with the added bonus of bypassing the cache.
But this does not solve the shell <-> browser communication problem, for that I used a python websocket server: the well known tornado server. The server is used to relay reload requests from the command line client to the listening extension in the browser all through websockets.
It looks like this:
As you can see the server is also used to watch over file modification using pyinotify.
For instance if you have told wsreload to watch over your
/tmp directory and to reload all the
http://localhost:1234/* pages with the following command:
a inotify watcher will be added to the
/tmp directory with the url query attach to it.
When a file change in
/tmp, inotify will tell the server and the server will send the corresponding query through all the connected websockets (opened by the browser extensions).
All the extensions will receive the query and try to match any open tab with it, reloading the one matching.
NB: The extension is also able to tell the server to watch for files when a url match the
That’s all for now.
Ask me if you have any question :)