UNPKG

2.72 kBMarkdownView Raw
1# browser-launcher
2
3Detect the browser versions available on your system and launch them in an
4isolated profile for automated testing purposes.
5
6You can launch browsers headlessly (if you have Xvfb or with phantom) and set
7the proxy configuration on the fly.
8
9# example
10
11``` js
12var launcher = require('launcher');
13launcher(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
66var launcher = require('launcher')
67```
68
69## launcher(cb)
70
71Create a new launcher function in `cb(err, launch)`, scanning for system
72browsers if no `~/.config/browser-launcher/config.json` is present and reading
73from that file otherwise.
74
75## launch(uri, opts, cb)
76
77Launch a new instance of `opts.browser` with the optional version constraint
78`opts.version`. Without an `opts.version`, the highest version of `opts.browser`
79is used.
80
81To launch the browser headlessly (if it isn't already headless like phantom),
82set `opts.headless`. This launches the browser with
83[node-headless](https://github.com/kesla/node-headless/)
84which uses the `Xvfb` command to create a fake X server.
85
86To use the browser with a proxy, set `opts.proxy` as a colon-separated
87`'host:port'` string.
88
89Set proxy routes to skip over with `opts.noProxy`.
90
91`cb` fires with `cb(err, ps)` where `ps` is the process object created with
92`spawn()`.
93
94## launch.browsers
95
96This property shows what browsers are configured to be launchable, divided into
97groups. The default group is `'local'`.
98
99# install
100
101```
102npm install browser-launcher
103```
104
105# license
106
107MIT