1 | # browser-launcher
|
2 |
|
3 | Detect the browser versions available on your system and launch them in an
|
4 | isolated profile for automated testing purposes.
|
5 |
|
6 | You can launch browsers headlessly (if you have Xvfb or with phantom) and set
|
7 | the proxy configuration on the fly.
|
8 |
|
9 | # example
|
10 |
|
11 | ``` js
|
12 | var launcher = require('launcher');
|
13 | launcher(function (err, launch) {
|
14 | if (err) return console.error(err);
|
15 |
|
16 | console.log('# available browsers:');
|
17 | console.dir(launch.browsers);
|
18 |
|
19 | var opts = {
|
20 | headless : true,
|
21 | browser : 'chrome',
|
22 | proxy : 'localhost:7077',
|
23 | };
|
24 | launch('http://substack.net', opts, function (err, ps) {
|
25 | if (err) return console.error(err);
|
26 | });
|
27 | });
|
28 | ```
|
29 |
|
30 | ***
|
31 |
|
32 | ```
|
33 | $ node example/launch.js
|
34 | # available browsers:
|
35 | { local:
|
36 | [ { name: 'chrome',
|
37 | re: {},
|
38 | type: 'chrome',
|
39 | profile: '/home/substack/.config/browser-launcher/chrome-17.0.963.12_9c0bdd8d',
|
40 | command: 'google-chrome',
|
41 | version: '17.0.963.12' },
|
42 | { name: 'chromium',
|
43 | re: {},
|
44 | type: 'chrome',
|
45 | profile: '/home/substack/.config/browser-launcher/chromium-18.0.1025.168_e025d855',
|
46 | command: 'chromium-browser',
|
47 | version: '18.0.1025.168' },
|
48 | { name: 'phantom',
|
49 | re: {},
|
50 | type: 'phantom',
|
51 | headless: true,
|
52 | profile: '/home/substack/.config/browser-launcher/phantom-1.4.0_31767fa2',
|
53 | command: 'phantomjs',
|
54 | version: '1.4.0' },
|
55 | { name: 'firefox',
|
56 | re: {},
|
57 | type: 'firefox',
|
58 | profile: [Object],
|
59 | command: 'firefox',
|
60 | version: '12.0' } ] }
|
61 | ```
|
62 |
|
63 | # methods
|
64 |
|
65 | ``` js
|
66 | var launcher = require('launcher')
|
67 | ```
|
68 |
|
69 | ## launcher(cb)
|
70 |
|
71 | Create a new launcher function in `cb(err, launch)`, scanning for system
|
72 | browsers if no `~/.config/browser-launcher/config.json` is present and reading
|
73 | from that file otherwise.
|
74 |
|
75 | ## launch(uri, opts, cb)
|
76 |
|
77 | Launch a new instance of `opts.browser` with the optional version constraint
|
78 | `opts.version`. Without an `opts.version`, the highest version of `opts.browser`
|
79 | is used.
|
80 |
|
81 | To launch the browser headlessly (if it isn't already headless like phantom),
|
82 | set `opts.headless`. This launches the browser with
|
83 | [node-headless](https://github.com/kesla/node-headless/)
|
84 | which uses the `Xvfb` command to create a fake X server.
|
85 |
|
86 | To use the browser with a proxy, set `opts.proxy` as a colon-separated
|
87 | `'host:port'` string.
|
88 |
|
89 | `cb` fires with `cb(err, ps)` where `ps` is the process object created with
|
90 | `spawn()`.
|
91 |
|
92 | ## launch.browsers
|
93 |
|
94 | This property shows what browsers are configured to be launchable, divided into
|
95 | groups. The default group is `'local'`.
|
96 |
|
97 | # install
|
98 |
|
99 | ```
|
100 | npm install browser-launcher
|
101 | ```
|
102 |
|
103 | # license
|
104 |
|
105 | MIT
|