osx-browser-vm
v1.0.8
Published
Evaluate JavaScript in local OS X browsers
Downloads
7
Readme
os-browser-vm
This library lets you evaluate arbitary JavaScript on the browsers installed on your local OS X machine, through Node.js. It currently supports Safari, Google Chrome, and Google Chrome Canary (Firefox support is apparently not possible). It works thanks to support for JavaScript automation in modern releases of OS X, and is similar to the Node.js vm module.
API
This library exports three properties: safari
, chrome
, and canary
.
{safari|chrome|canary}.run(code, callback)
code
is the JavaScript string to be evaluated. The result of the last expression in this string is passed to the callback
in the usual Node.js (err, data)
signature.
A function can also be passed for code
, in which case it is stringified as an IIFE.
Example
import {safari, chrome, canary} from 'osx-browser-vm'
var vms = [safari, chrome, canary]
var code = 'Object.getOwnPropertyNames(window).length'
console.log("Number of properties on window:")
vms.forEach(vm => {
vm.run(code, (err, count) => {
console.log("- %s: %s", vm.name, count)
})
})
// Number of properties on window:
// - Google Chrome Canary: 694
// - Google Chrome: 682
// - Safari: 607