forked from browserless/browserless
-
Notifications
You must be signed in to change notification settings - Fork 0
/
env.js
151 lines (124 loc) · 4 KB
/
env.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/* eslint-disable no-undef */
/* eslint-disable no-useless-escape */
const os = require('os');
const playwright = require('playwright-core');
const puppeteer = require('puppeteer');
const pptrPackageJSON = require('puppeteer/package.json');
const pptrVersion = pptrPackageJSON.version;
const packageJson = require('./package.json');
const IS_DOCKER = process.env.IS_DOCKER === 'true';
const USE_CHROME_STABLE = process.env.USE_CHROME_STABLE && process.env.USE_CHROME_STABLE === 'true';
const MAC = 'MAC';
const WINDOWS = 'WINDOWS';
const LINUX = 'LINUX';
const LINUX_ARM64 = 'LINUX_ARM64';
const CHROME_BINARY_PATHS = {
LINUX: '/usr/bin/google-chrome',
MAC: '/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome',
WIN: 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe',
};
const PLATFORM = os.platform() === 'win32' ?
WINDOWS :
os.platform() === 'darwin' ?
MAC :
os.arch() === 'arm64' ?
LINUX_ARM64 :
LINUX;
/*
* Assess which chromium revision to install.
* Note that in docker we do our own install, and
* ignore puppeteer's install.js file.
*/
const PUPPETEER_CHROMIUM_REVISION = (() => {
if (process.env.PUPPETEER_CHROMIUM_REVISION) {
return process.env.PUPPETEER_CHROMIUM_REVISION;
}
if (USE_CHROME_STABLE) {
return packageJson.chromeVersions['chrome-stable'].chromeRevision;
}
const pinnedRevision = packageJson.chromeVersions[`puppeteer-${pptrVersion}`];
if (pinnedRevision) {
return pinnedRevision.chromeRevision;
}
if (pptrPackageJSON.puppeteer) {
return pptrPackageJSON.puppeteer.chromium_revision;
}
if (puppeteer._preferredRevision) {
return puppeteer._preferredRevision;
}
const pptr = require('./node_modules/puppeteer/lib/cjs/puppeteer/revisions');
return pptr.PUPPETEER_REVISIONS.chromium;
})();
/*
* Sometimes we don't use puppeteer's built-in chromium
* for compatibility reasons
*/
const PUPPETEER_BINARY_LOCATION = (() => {
if (PLATFORM === LINUX_ARM64) {
return playwright.chromium.executablePath();
}
const browserFetcher = puppeteer.createBrowserFetcher();
return browserFetcher.revisionInfo(PUPPETEER_CHROMIUM_REVISION).executablePath;
})();
/*
* Tells puppeteer, in its install script, what revision to download.
* This is set in our deploy.js file in our docker build. If
* PUPPETEER_SKIP_CHROMIUM_DOWNLOAD is true, then this is ignored
*/
const CHROME_BINARY_LOCATION = (() => {
if (process.env.CHROME_BINARY_LOCATION) {
return process.env.CHROME_BINARY_LOCATION;
}
// In docker we symlink any chrome installs to the default install location
// so that chromedriver can do its thing
if (IS_DOCKER) {
return CHROME_BINARY_PATHS.LINUX;
}
// If using chrome-stable, default to it's natural habitat
if (USE_CHROME_STABLE) {
return CHROME_BINARY_PATHS[PLATFORM];
}
// All else uses pptr's bin
return PUPPETEER_BINARY_LOCATION;
})();
/*
* Tells the chromedriver library to download the appropriate chromedriver binary.
* The only time this should be false is when building chrome stable in docker.
*/
const CHROMEDRIVER_SKIP_DOWNLOAD = (() => {
if (process.env.CHROMEDRIVER_SKIP_DOWNLOAD) {
return process.env.CHROMEDRIVER_SKIP_DOWNLOAD;
}
if (IS_DOCKER) {
return !USE_CHROME_STABLE;
}
return true;
})();
/*
* Tells puppeteer to skip downloading the appropriate chrome revision. This is generally
* not the case, however when installing chrome-stable in docker we want to skip it as
* we'll download google-chrome-stable from a deb package instead.
*/
const PUPPETEER_SKIP_CHROMIUM_DOWNLOAD = (() => {
if (process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD) {
return process.env.PUPPETEER_SKIP_CHROMIUM_DOWNLOAD;
}
if (IS_DOCKER) {
return USE_CHROME_STABLE;
}
return false;
})();
module.exports = {
IS_DOCKER,
USE_CHROME_STABLE,
PUPPETEER_CHROMIUM_REVISION,
CHROME_BINARY_LOCATION,
CHROMEDRIVER_SKIP_DOWNLOAD,
PUPPETEER_SKIP_CHROMIUM_DOWNLOAD,
PUPPETEER_BINARY_LOCATION,
PLATFORM,
WINDOWS,
MAC,
LINUX,
LINUX_ARM64,
};