The coolest thing about electron is that it blurs the line between "Node" and "Browser." Here is a Node.js module that typically doesn't work in the browser, but runs as expected in Electron:
var natural = require('natural')
console.log(natural.LevenshteinDistance('one', 'one'))
Example output:
It also means that, during development, we can have the full range of Chrome DevTools at our fingertips: debugging, profiling, Network requests, etc.
Maybe this concept could eventually grow into a larger platform like Cinder or Plask. It could be used to build various rich media experiences (art installations, prints, games, etc) that seamlessly integrate libraries like three.js (browser) and node-opencv (node).
A quick proof of concept shows this isn't too far off. The demo reads an image from disk using fs
, processes it using WebGL shaders, and saves the new HTML canvas to a file. It's in "interactive" or development mode (using hihat), so that reloading the source will re-run the program. But the end product would just run once, eg:
shaderize ./original.png --frag ./grayscale.glsl --out foo-gray.png
Other tools could leverage SVG rendering, Speech recognition/synthesization, WebAudio, Canvas2D, GamePad APIs, DeviceMotion, WebRTC, video playback/processing, etc. Or, Electron-specific APIs like taking a screenshot of the page (could be useful for testing purposes).
Some areas that still need to be figured out:
- most use cases of Chrome/Electron are focused on larger GUI apps like Atom, Slack, etc that stay open until the user closes them, and ask for input via GUI (like an Open Dialog)
- getting Chrome/Electron to run "headlessly" is a bit clunky
- using
browserify
orwebpack
rather than Electron's standard node integration is desirable to take advantage of transforms and loaders- these bundlers will not resolve
require('fs')
correctly window.require('fs')
still works, but this is not good since Node.js modules will not work correctly- it can lead to some surprises since both Browserify and Electron are doing some magical things to make your Node.js code work
- these bundlers will not resolve
- how to pass user options/flags to the Electron instance?
- having a better
process
shim:process.argv
,process.cwd()
should work correctly
- should the bundler respect the browser field or not?
- is it possible to handle
process.stdin
andprocess.stdout
for things like piping images around? - will this ever work on a server?
already works on a server :)
xvfb-run electron-spawn app.js