Tag Archives: javascript

Loading webcomponents-lite with require()

I just realised that the Web Components polyfills not only are in npm so you can install them like this:

npm install --save webcomponents-lite

but they also have a well formed package.json with a main entry.

So if you’re writing your front-end code with Browserify and want to load the polyfill without adding an additional script tag, you can do this:

require('webcomponents-lite');

and this pulls the polyfill into the scope.

NICE! Thanks, Addy :-)

PS I guess this should also work with webpack, if you’re so inclined.

Running a web server on the front-end

The introduction of TCP sockets support in Firefox OS made it possible to run a web server from the front-end, and all is written in JavaScript. Think of having something similar to express.js… but running on a browser (because after all, Firefox OS is a superturbocharged browser).

Again, JS server superstar Justin d’Archangelo wrote an implementation of a web server that works on Firefox OS. It’s called fxos-web-server and it includes a few examples you can run.

None of the examples particularly fit my use case–I want to serve static content from a phone to other phones, but the examples were a bit more contrived. So I decided to build a simpler proof-of-concept example: catserver, a web server that served a simple page with full screen Animated GIFs of cats:

Continue reading

Getting logs of your Firefox OS device

Often you want to output debugging data from your app, but the space on the screen is limited! And perhaps you don’t want to connect to the app with WebIDE and launch the debugger and etc, etc…

One solution is to use any of the console. functions in your code. They will be sent to the device’s log. For example:

console.log('hello friends!');

and you can also use console.error, console.info, etc.

Then, if you have the adb utility installed, you can get instant access to those logs when your device is connected to your computer with USB.
Continue reading

Front-end mDNS: announcing and finding network services with JavaScript

Multicast DNS (or mDNS) lets you announce a service you’re offering in the network you’re connected to, and other devices can find (discover) it. For example, you could announce that your computer is running an FTP service. It’s the same thing that Apple does with its Bonjour protocol and that’s how you can find printers without knowing their IP address: they broadcast their existence, and your computer picks it up automatically for you.

Services have to be registered with a domain ending in .local. E.g. _ssh._tcp.local. The Wikipedia page has some background on why.

However, the title of this post has “front-end” on it, and that’s because I wanted to talk about dns-sd.js, a library that lets you both register and discover services in the network. It’s all written in JavaScript so it can run on a browser environment, in this case Firefox OS.
Continue reading

install-to-adb with command line tool!

As I said, I abhor repetition, so I added a new nifty feature to the install-to-adb module I made.

Now it also has a command line tool, and you can push and launch apps from the command line without even having to write a custom script that uses the module (of course, you can still use the module code by requiring it).

install-to-adb /path/to/your/firefoxos/app --launch

Continue reading