Code Monkey home page Code Monkey logo

node-firefox-start-simulator's Introduction

node-firefox-start-simulator Build Status

Start a Firefox OS simulator.

Install with NPM

This is part of the node-firefox project.

Installation

From git

git clone https://github.com/mozilla/node-firefox-start-simulator.git
cd node-firefox-start-simulator
npm install

If you want to update later on:

cd node-firefox-start-simulator
git pull origin master
npm install

npm

npm install node-firefox-start-simulator

Usage

var startSimulator = require('node-firefox-start-simulator');

// `startSimulator` returns a Promise
startSimulator(options).then(function(simulator) {

});

where options is a plain Object with any of the following:

  • detached: start the simulator as a detached process. If our script is killed, the simulator will still be running.
  • port: make the simulator listen to this port for debugging. If not specified, we'll find an available port.
  • version: start a simulator in this version. If not specified, we'll start the first simulator that we can find.
  • verbose: pipe the output from the simulator to standard I/O. For example, you'll get JavaScript console.log messages executed in the simulator.

and simulator is an object containing:

  • binary: path to the simulator binary
  • bin: an alias to binary
  • profile: path to the simulator profile
  • pid: process id
  • process: the actual process object
  • port: the port where the simulator is listening for debugging connections

There is also a startSimulator.all() utility to launch many simulators at once:

startSimulator.all(options)(simulatorOptions)
  .then(function(launchedSimulators) {
    // launchedSimulators is a list of simulator objects
  });

The options parameter here is the same as above - these options will be commonly applied to all the simulators launched.

The call to startSimulator.all() returns a function that takes a list of simulators and returns a Promise to launch them all. The result of that Promise is launchedSimulators, a list of all the simulators that were launched.

Note: This function returning a function may seem like a roundabout way to do things, but take a look at the examples below to see how this works with findSimulators() and other Promise-based APIs.

Examples

Start any simulator on the first available port

var startSimulator = require('node-firefox-start-simulator');

startSimulator().then(function(simulator) {
  console.log('Started simulator at port', simulator.port);
}, function(err) {
  console.log('Error starting a simulator', err);
});

Start all simulators found on your system

var findSimulators = require('node-firefox-find-simulators');
var startSimulator = require('node-firefox-start-simulator');

// startSimulator.all() returns a function that applies the common options to
// all the simulators discovered by findSimulators()

findSimulators.then(startSimulator.all({ detached: true }));

Have a look at the examples folder for more!

Documentation

If you want to contribute to this module, it might be interesting to have a look at the way WebIDE launches the simulator. The code for this is in simulator-process.js. Whenever possible, we want to mimic the WebIDE experience as closely as possible.

History

This is based on initial work on fxos-start by Nicola Greco.

node-firefox-start-simulator's People

Contributors

brittanydionigi avatar lmorchard avatar nicola avatar rodms10 avatar sole avatar tofumatt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-firefox-start-simulator's Issues

Review and update all examples

Some of them are updated to work with the new interface and some aren't.

Also some rely on a client object being returned by the function that starts the simulator, but this functionality should be in a different module.

Error: connect ECONNREFUSED

I get this sometimes

node-firefox-start-simulator/index.js:143
            throw error;
                  ^
Error: connect ECONNREFUSED
    at errnoException (net.js:904:11)
    at Object.afterConnect [as oncomplete] (net.js:895:19)

Implement timeout parameter?

Currently (in my branch, hopefully soon on master) the timeout is hardcoded to 25 seconds. Do we want to pass that as a parameter too?

listTabs example times out

Ran into an issue running this:

https://github.com/mozilla/node-firefox-start-simulator/blob/master/examples/startAndListApps.js

The b2g window comes up but I never see a gaia and starting eventually times out with:

Error starting simulator [Error: Timed out trying to connect to the simulator in 8002]

I enabled more verbose output by setting that flag here:

Error starting simulator [Error: Timed out trying to connect to the simulator in 8002]

..eg { port: 8002, verbose: true } as the options object. The I get:

{ binary: '/Users/jeff/Library/Application Support/Firefox/Profiles/0kx955xu.dev-edition-default/extensions/[email protected]/b2g/B2G.app/Contents/MacOS/b2g-bin',
  profile: '/Users/jeff/Library/Application Support/Firefox/Profiles/0kx955xu.dev-edition-default/extensions/[email protected]/profile',
  port: 8002,
  detached: false,
  verbose: true }
1422318112061   Marionette  INFO    marionette enabled via build flag and pref
1422318112102   Marionette  INFO    marionette-server.js loaded
1422318112134   Marionette  INFO    Listening on port 2828

1422318112134   Marionette  INFO    Marionette server ready
System JS : WARNING resource://gre/modules/Preferences.jsm:378 - mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create
###################################### forms.js loaded
############################### browserElementPanning.js loaded
######################## BrowserElementChildPreload.js loaded
*** UTM:SVC TimerManager:registerTimer - id: user-agent-updates-timer
************************************************************
* Call to xpconnect wrapped JSObject produced this error:  *
[Exception... "[JavaScript Error: "allocation size overflow" {file: "file:///Users/jeff/Library/Application%20Support/Firefox/Profiles/0kx955xu.dev-edition-default/extensions/[email protected]/b2g/B2G.app/Contents/MacOS/components/B2GAboutRedirector.js" line: 41}]'[JavaScript Error: "allocation size overflow" {file: "file:///Users/jeff/Library/Application%20Support/Firefox/Profiles/0kx955xu.dev-edition-default/extensions/[email protected]/b2g/B2G.app/Contents/MacOS/components/B2GAboutRedirector.js" line: 41}]' when calling method: [nsIAboutModule::getURIFlags]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  location: "JS frame :: chrome://b2g/content/shell.js :: shell_start :: line 310"  data: yes]
************************************************************
Error starting simulator [Error: Timed out trying to connect to the simulator in 8002]
************************************************************
* Call to xpconnect wrapped JSObject produced this error:  *
[Exception... "[JavaScript Error: "allocation size overflow" {file: "file:///Users/jeff/Library/Application%20Support/Firefox/Profiles/0kx955xu.dev-edition-default/extensions/[email protected]/b2g/B2G.app/Contents/MacOS/components/B2GAboutRedirector.js" line: 41}]'[JavaScript Error: "allocation size overflow" {file: "file:///Users/jeff/Library/Application%20Support/Firefox/Profiles/0kx955xu.dev-edition-default/extensions/[email protected]/b2g/B2G.app/Contents/MacOS/components/B2GAboutRedirector.js" line: 41}]' when calling method: [nsIAboutModule::newChannel]"  nsresult: "0x80570021 (NS_ERROR_XPC_JAVASCRIPT_ERROR_WITH_DETAILS)"  location: "JS frame :: chrome://b2g/content/shell.js :: shell_start :: line 310"  data: yes]
************************************************************
*** UTM:SVC TimerManager:notify - notified @mozilla.org/extensions/blocklist;1
*** UTM:SVC TimerManager:notify - notified timerID: user-agent-updates-timer
*** UTM:SVC TimerManager:registerTimer - id: user-agent-updates-timer

Would be nice to be able to specify a position for the simulator window

When we start a simulator they always start on the same position on the screen. I wonder if there's some option in the simulator binary to specify a different position so they don't overlap and we don't need to rearrange them manually in order to be able to see them all at the same time.

Simplify using startSimulator with findSimulators?

So, I'd like to do something like this:

findSimulators({ version: ['2.1', '2.2'] }).then(startSimulators);

But, I have to write glue code to adapt output from findSimulators to startSimulator:

  // Find and start ALL the simulators
  findSimulators({ version: ['2.1', '2.2'] }).then(function (simulators) {
    // Hmm, this could probably be simpler if the output of findSimulator
    // matched the input of startSimulator
    return Promise.all(simulators.map(function (simulator) {
      return startSimulator({
        binary: simulator.bin,
        profile: simulator.profile
      });
    }));
  })

If this sounds like a useful tweak, I think the way to get there is with two changes:

  • If Array.isArray(options) === true in startSimulator, then return Promise.all(options.map(startSimulator)) to start a set of simulators.
  • Support options.bin as a synonym for options.binary to match the output of findSimulators()
    • Alternatively, rename bin to binary in the output of findSimulators() - cleaner, but backwards-incompatible. Maybe not a big deal, since we're early on with things here

Thoughts? Good idea? Bad idea?

Renaming to node-firefox-start-simulator

I'd suggest changing the name of this module to start-simulator as it is more obvious what it does.

I had the same "issue" with fx-simulators which I renamed to find-simulators and makes more sense when you require it.

So you could do:

var startSimulator = require('node-firefox-start-simulator');

CODE_OF_CONDUCT.md file missing

As of January 1 2019, Mozilla requires that all GitHub projects include this CODE_OF_CONDUCT.md file in the project root. The file has two parts:

  1. Required Text - All text under the headings Community Participation Guidelines and How to Report, are required, and should not be altered.
  2. Optional Text - The Project Specific Etiquette heading provides a space to speak more specifically about ways people can work effectively and inclusively together. Some examples of those can be found on the Firefox Debugger project, and Common Voice. (The optional part is commented out in the raw template file, and will not be visible until you modify and uncomment that part.)

If you have any questions about this file, or Code of Conduct policies and procedures, please see Mozilla-GitHub-Standards or email [email protected].

(Message COC001)

Add support for Windows

I am not familiar with any potential huge architectural differences between launching processes with Windows vs "POSIX" like Mac OS/Linux. Hopefully it will work the same, but I am not 100% sure we get things such as a PID that we can use to kill processes later in Windows.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.