camoucore 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/THIRD_PARTY_NOTICES.md +64 -0
- package/dist/cpu_affinity.d.ts +49 -0
- package/dist/cpu_affinity.js +210 -0
- package/dist/data-files/fpgen-model.json +22 -0
- package/dist/data-files/geoip.yml +40 -0
- package/dist/data-files/territoryInfo.xml +2024 -0
- package/dist/data-files/warnings.yml +14 -0
- package/dist/data.d.ts +5 -0
- package/dist/data.js +22 -0
- package/dist/display.d.ts +18 -0
- package/dist/display.js +129 -0
- package/dist/download.d.ts +60 -0
- package/dist/download.js +233 -0
- package/dist/exceptions.d.ts +46 -0
- package/dist/exceptions.js +91 -0
- package/dist/geolocation.d.ts +82 -0
- package/dist/geolocation.js +355 -0
- package/dist/host.d.ts +9 -0
- package/dist/host.js +49 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/ip.d.ts +27 -0
- package/dist/ip.js +302 -0
- package/dist/locales.d.ts +89 -0
- package/dist/locales.js +343 -0
- package/dist/product.d.ts +27 -0
- package/dist/product.js +36 -0
- package/dist/virtdisplay.d.ts +74 -0
- package/dist/virtdisplay.js +310 -0
- package/dist/warnings.d.ts +32 -0
- package/dist/warnings.js +68 -0
- package/package.json +61 -0
package/dist/locales.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Locale data structures, validation and the statistical locale selector.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript twin of python/src/camoucore/locales.py.
|
|
5
|
+
*/
|
|
6
|
+
import * as fs from "node:fs";
|
|
7
|
+
import * as path from "node:path";
|
|
8
|
+
import tags from "language-tags";
|
|
9
|
+
import xml2js from "xml2js";
|
|
10
|
+
import { LOCAL_DATA } from "./data.js";
|
|
11
|
+
import { InvalidLocale, UnknownLanguage, UnknownTerritory, } from "./exceptions.js";
|
|
12
|
+
import { LeakWarning, loadWarnings } from "./warnings.js";
|
|
13
|
+
/*
|
|
14
|
+
* Data structures for locale and geolocation info
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Stores locale, region, and script information.
|
|
18
|
+
*/
|
|
19
|
+
export class Locale {
|
|
20
|
+
language;
|
|
21
|
+
region;
|
|
22
|
+
script;
|
|
23
|
+
constructor(language, region, script) {
|
|
24
|
+
this.language = language;
|
|
25
|
+
this.region = region;
|
|
26
|
+
this.script = script;
|
|
27
|
+
}
|
|
28
|
+
get asString() {
|
|
29
|
+
if (this.region) {
|
|
30
|
+
return `${this.language}-${this.region}`;
|
|
31
|
+
}
|
|
32
|
+
return this.language;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Converts the locale to an intl config object.
|
|
36
|
+
*/
|
|
37
|
+
asConfig() {
|
|
38
|
+
if (!this.region) {
|
|
39
|
+
throw new Error("AssertionError: Locale.asConfig() needs a region");
|
|
40
|
+
}
|
|
41
|
+
const data = {
|
|
42
|
+
"locale:region": this.region,
|
|
43
|
+
"locale:language": this.language,
|
|
44
|
+
};
|
|
45
|
+
if (this.script) {
|
|
46
|
+
data["locale:script"] = this.script;
|
|
47
|
+
}
|
|
48
|
+
return data;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Stores geolocation information.
|
|
53
|
+
*/
|
|
54
|
+
export class Geolocation {
|
|
55
|
+
locale;
|
|
56
|
+
longitude;
|
|
57
|
+
latitude;
|
|
58
|
+
timezone;
|
|
59
|
+
accuracy;
|
|
60
|
+
constructor(locale, longitude, latitude, timezone, accuracy) {
|
|
61
|
+
this.locale = locale;
|
|
62
|
+
this.longitude = longitude;
|
|
63
|
+
this.latitude = latitude;
|
|
64
|
+
this.timezone = timezone;
|
|
65
|
+
this.accuracy = accuracy;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Converts the geolocation to a config object.
|
|
69
|
+
*/
|
|
70
|
+
asConfig() {
|
|
71
|
+
const data = {
|
|
72
|
+
"geolocation:longitude": this.longitude,
|
|
73
|
+
"geolocation:latitude": this.latitude,
|
|
74
|
+
timezone: this.timezone,
|
|
75
|
+
...this.locale.asConfig(),
|
|
76
|
+
};
|
|
77
|
+
if (this.accuracy) {
|
|
78
|
+
data["geolocation:accuracy"] = this.accuracy;
|
|
79
|
+
}
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/*
|
|
84
|
+
* Helpers to validate and normalize locales
|
|
85
|
+
*/
|
|
86
|
+
/**
|
|
87
|
+
* Verifies that a locale is valid. Takes either language-region or language.
|
|
88
|
+
*/
|
|
89
|
+
function verifyLocale(loc) {
|
|
90
|
+
if (tags.check(loc)) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
throw InvalidLocale.invalidInput(loc);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Normalizes and validates a locale code.
|
|
97
|
+
*
|
|
98
|
+
* The script is the LANGUAGE's Suppress-Script ("Latn" for "en"), exactly as
|
|
99
|
+
* pythonlib does -- not the tag's explicit script subtag. Parity note: that
|
|
100
|
+
* makes "en-US" come out as en/Latn/US, and "zh-Hans-CN" as zh/(none)/CN.
|
|
101
|
+
*/
|
|
102
|
+
export function normalizeLocale(locale) {
|
|
103
|
+
verifyLocale(locale);
|
|
104
|
+
// Parse the locale
|
|
105
|
+
const parser = tags(locale);
|
|
106
|
+
const region = parser.region();
|
|
107
|
+
if (!region) {
|
|
108
|
+
throw InvalidLocale.invalidInput(locale);
|
|
109
|
+
}
|
|
110
|
+
const language = parser.language();
|
|
111
|
+
if (!language) {
|
|
112
|
+
throw InvalidLocale.invalidInput(locale);
|
|
113
|
+
}
|
|
114
|
+
const suppressScript = language.script();
|
|
115
|
+
// Return a formatted locale object
|
|
116
|
+
return new Locale(language.format(), region.format(), suppressScript ? suppressScript.format() : undefined);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Handles a locale input, normalizing it if necessary.
|
|
120
|
+
*/
|
|
121
|
+
export async function handleLocale(locale, ignoreRegion = false) {
|
|
122
|
+
// If the caller passed `language-region` or `language-script-region`, normalize it.
|
|
123
|
+
if (locale.length > 3) {
|
|
124
|
+
return normalizeLocale(locale);
|
|
125
|
+
}
|
|
126
|
+
// Case: caller passed a `region` and needs a full locale
|
|
127
|
+
try {
|
|
128
|
+
return await SELECTOR.fromRegion(locale);
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
if (!(e instanceof UnknownTerritory))
|
|
132
|
+
throw e;
|
|
133
|
+
}
|
|
134
|
+
// Case: caller passed a `language`, and doesn't care about the region
|
|
135
|
+
if (ignoreRegion) {
|
|
136
|
+
verifyLocale(locale);
|
|
137
|
+
return new Locale(locale);
|
|
138
|
+
}
|
|
139
|
+
// Case: caller passed a `language` and wants a region
|
|
140
|
+
let language;
|
|
141
|
+
try {
|
|
142
|
+
language = await SELECTOR.fromLanguage(locale);
|
|
143
|
+
}
|
|
144
|
+
catch (e) {
|
|
145
|
+
if (!(e instanceof UnknownLanguage))
|
|
146
|
+
throw e;
|
|
147
|
+
}
|
|
148
|
+
if (language) {
|
|
149
|
+
LeakWarning.warn(loadWarnings().no_region);
|
|
150
|
+
return language;
|
|
151
|
+
}
|
|
152
|
+
// Locale is not in a valid format.
|
|
153
|
+
throw InvalidLocale.invalidInput(locale);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Handles a list of locales, writing them into the config.
|
|
157
|
+
*/
|
|
158
|
+
export async function handleLocales(locales, config) {
|
|
159
|
+
const list = typeof locales === "string"
|
|
160
|
+
? locales.split(",").map((loc) => loc.trim())
|
|
161
|
+
: locales;
|
|
162
|
+
// First, handle the first locale. This will be used for the intl api.
|
|
163
|
+
const intlLocale = await handleLocale(list[0]);
|
|
164
|
+
Object.assign(config, intlLocale.asConfig());
|
|
165
|
+
if (list.length < 2) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
// If additional locales were passed, validate them.
|
|
169
|
+
// Note: in this case, we do not need the region.
|
|
170
|
+
const resolved = [];
|
|
171
|
+
for (const locale of list) {
|
|
172
|
+
resolved.push((await handleLocale(locale, true)).asString);
|
|
173
|
+
}
|
|
174
|
+
config["locale:all"] = joinUnique(resolved);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Joins a sequence of strings without duplicates.
|
|
178
|
+
*/
|
|
179
|
+
function joinUnique(seq) {
|
|
180
|
+
return [...new Set(seq)].join(", ");
|
|
181
|
+
}
|
|
182
|
+
let unicodeInfo = null;
|
|
183
|
+
/**
|
|
184
|
+
* Fetches supplemental data from the territoryInfo.xml file.
|
|
185
|
+
* Source: https://raw.githubusercontent.com/unicode-org/cldr/master/common/supplemental/supplementalData.xml
|
|
186
|
+
*/
|
|
187
|
+
function getUnicodeInfo() {
|
|
188
|
+
if (!unicodeInfo) {
|
|
189
|
+
unicodeInfo = (async () => {
|
|
190
|
+
const data = await fs.promises.readFile(path.join(LOCAL_DATA, "territoryInfo.xml"));
|
|
191
|
+
const parsed = await new xml2js.Parser().parseStringPromise(data);
|
|
192
|
+
const territories = parsed?.territoryInfo?.territory;
|
|
193
|
+
if (!territories) {
|
|
194
|
+
throw new Error("Failed to load territoryInfo.xml");
|
|
195
|
+
}
|
|
196
|
+
return territories;
|
|
197
|
+
})();
|
|
198
|
+
}
|
|
199
|
+
return unicodeInfo;
|
|
200
|
+
}
|
|
201
|
+
/** float(element.get(attr, 0)) */
|
|
202
|
+
function asFloat(attrs, attr) {
|
|
203
|
+
const raw = attrs[attr];
|
|
204
|
+
if (raw === undefined)
|
|
205
|
+
return 0;
|
|
206
|
+
const value = Number(raw.trim());
|
|
207
|
+
if (Number.isNaN(value)) {
|
|
208
|
+
throw new Error(`could not convert string to float: '${raw}'`);
|
|
209
|
+
}
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* numpy's pairwise summation (np.sum over a 1-D float64 array), so the
|
|
214
|
+
* normalised probabilities are bit-identical to the Python selector's.
|
|
215
|
+
*/
|
|
216
|
+
export function pairwiseSum(values) {
|
|
217
|
+
const sum = (lo, n) => {
|
|
218
|
+
if (n < 8) {
|
|
219
|
+
let res = 0;
|
|
220
|
+
for (let i = 0; i < n; i++)
|
|
221
|
+
res += values[lo + i];
|
|
222
|
+
return res;
|
|
223
|
+
}
|
|
224
|
+
if (n <= 128) {
|
|
225
|
+
const r = values.slice(lo, lo + 8);
|
|
226
|
+
let i = 8;
|
|
227
|
+
for (; i < n - (n % 8); i += 8) {
|
|
228
|
+
for (let j = 0; j < 8; j++)
|
|
229
|
+
r[j] += values[lo + i + j];
|
|
230
|
+
}
|
|
231
|
+
let res = r[0] + r[1] + (r[2] + r[3]) + (r[4] + r[5] + (r[6] + r[7]));
|
|
232
|
+
for (; i < n; i++)
|
|
233
|
+
res += values[lo + i];
|
|
234
|
+
return res;
|
|
235
|
+
}
|
|
236
|
+
let n2 = Math.floor(n / 2);
|
|
237
|
+
n2 -= n2 % 8;
|
|
238
|
+
return sum(lo, n2) + sum(lo + n2, n - n2);
|
|
239
|
+
};
|
|
240
|
+
return sum(0, values.length);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Injection point for the selector's one random draw (tests pin it).
|
|
244
|
+
* `random()` plays numpy's RandomState.random_sample().
|
|
245
|
+
*/
|
|
246
|
+
export const localeDeps = {
|
|
247
|
+
random: () => Math.random(),
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* numpy.random.choice(items, p=probabilities): searchsorted(right) of one
|
|
251
|
+
* uniform draw in the renormalised CDF.
|
|
252
|
+
*/
|
|
253
|
+
export function weightedChoice(items, p) {
|
|
254
|
+
const cdf = [];
|
|
255
|
+
let acc = 0;
|
|
256
|
+
for (const x of p) {
|
|
257
|
+
acc += x;
|
|
258
|
+
cdf.push(acc);
|
|
259
|
+
}
|
|
260
|
+
const last = cdf[cdf.length - 1];
|
|
261
|
+
for (let i = 0; i < cdf.length; i++)
|
|
262
|
+
cdf[i] /= last;
|
|
263
|
+
const u = localeDeps.random();
|
|
264
|
+
let idx = 0;
|
|
265
|
+
while (idx < cdf.length && cdf[idx] <= u)
|
|
266
|
+
idx++;
|
|
267
|
+
return items[Math.min(idx, items.length - 1)];
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Selects a random locale based on statistical data. Takes either a territory
|
|
271
|
+
* code or a language code, and generates a Locale.
|
|
272
|
+
*/
|
|
273
|
+
export class StatisticalLocaleSelector {
|
|
274
|
+
/**
|
|
275
|
+
* Calculates a random language based on the territory code, based on the
|
|
276
|
+
* probability that a person speaks the language in the territory.
|
|
277
|
+
*/
|
|
278
|
+
async loadTerritoryData(isoCode) {
|
|
279
|
+
const territories = await getUnicodeInfo();
|
|
280
|
+
const territory = territories.find((t) => t.$?.type === isoCode);
|
|
281
|
+
if (!territory) {
|
|
282
|
+
throw new UnknownTerritory(`Unknown territory: ${isoCode}`);
|
|
283
|
+
}
|
|
284
|
+
const langPopulations = territory.languagePopulation;
|
|
285
|
+
if (!langPopulations?.length) {
|
|
286
|
+
throw new Error(`No language data found for region: ${isoCode}`);
|
|
287
|
+
}
|
|
288
|
+
const languages = langPopulations.map((lang) => lang.$.type);
|
|
289
|
+
const percentages = langPopulations.map((lang) => asFloat(lang.$, "populationPercent"));
|
|
290
|
+
return this.normalizeProbabilities(languages, percentages);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Calculates a random region for a language based on the total speakers of
|
|
294
|
+
* the language in that region.
|
|
295
|
+
*/
|
|
296
|
+
async loadLanguageData(language) {
|
|
297
|
+
const territories = (await getUnicodeInfo()).filter((t) => t.languagePopulation?.some((lp) => lp.$?.type === language));
|
|
298
|
+
if (!territories.length) {
|
|
299
|
+
throw new UnknownLanguage(`No region data found for language: ${language}`);
|
|
300
|
+
}
|
|
301
|
+
const regions = [];
|
|
302
|
+
const percentages = [];
|
|
303
|
+
for (const terr of territories) {
|
|
304
|
+
const region = terr.$?.type;
|
|
305
|
+
if (region === undefined)
|
|
306
|
+
continue; // Skip if region is not found
|
|
307
|
+
const langPop = terr.languagePopulation?.find((lp) => lp.$?.type === language);
|
|
308
|
+
if (!langPop)
|
|
309
|
+
continue;
|
|
310
|
+
regions.push(region);
|
|
311
|
+
percentages.push(((asFloat(langPop.$, "populationPercent") *
|
|
312
|
+
asFloat(terr.$, "literacyPercent")) /
|
|
313
|
+
10_000) *
|
|
314
|
+
asFloat(terr.$, "population"));
|
|
315
|
+
}
|
|
316
|
+
if (!regions.length) {
|
|
317
|
+
throw new Error(`No valid region data found for language: ${language}`);
|
|
318
|
+
}
|
|
319
|
+
return this.normalizeProbabilities(regions, percentages);
|
|
320
|
+
}
|
|
321
|
+
/** Normalize probabilities. */
|
|
322
|
+
normalizeProbabilities(items, freq) {
|
|
323
|
+
const total = pairwiseSum(freq);
|
|
324
|
+
return [items, freq.map((f) => f / total)];
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get a random locale based on the territory ISO code.
|
|
328
|
+
*/
|
|
329
|
+
async fromRegion(region) {
|
|
330
|
+
const [languages, probabilities] = await this.loadTerritoryData(region);
|
|
331
|
+
const language = weightedChoice(languages, probabilities).replaceAll("_", "-");
|
|
332
|
+
return normalizeLocale(`${language}-${region}`);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Get a random locale based on the language.
|
|
336
|
+
*/
|
|
337
|
+
async fromLanguage(language) {
|
|
338
|
+
const [regions, probabilities] = await this.loadLanguageData(language);
|
|
339
|
+
const region = weightedChoice(regions, probabilities);
|
|
340
|
+
return normalizeLocale(`${language}-${region}`);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
export const SELECTOR = new StatisticalLocaleSelector();
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface Engine {
|
|
2
|
+
readonly name: "firefox" | "chromium";
|
|
3
|
+
/**
|
|
4
|
+
* Xvfb's screen for headless="virtual" until the launcher fits it to the
|
|
5
|
+
* identity. Firefox's window size is spoofed, so a 1x1 root is enough;
|
|
6
|
+
* Chromium's window is real and has to fit on the display.
|
|
7
|
+
*/
|
|
8
|
+
readonly virtualScreen: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const FIREFOX: Engine;
|
|
11
|
+
export declare const CHROMIUM: Engine;
|
|
12
|
+
export declare class Product {
|
|
13
|
+
/** The package and cache name: "camoufox", "camouwolf". */
|
|
14
|
+
readonly name: string;
|
|
15
|
+
/** The name in messages: "Camoufox", "Camouwolf". */
|
|
16
|
+
readonly title: string;
|
|
17
|
+
readonly engine: Engine;
|
|
18
|
+
constructor(
|
|
19
|
+
/** The package and cache name: "camoufox", "camouwolf". */
|
|
20
|
+
name: string,
|
|
21
|
+
/** The name in messages: "Camoufox", "Camouwolf". */
|
|
22
|
+
title: string, engine: Engine);
|
|
23
|
+
get cacheDir(): string;
|
|
24
|
+
/** This launcher's name for an environment variable: CAMOUWOLF_<key>. */
|
|
25
|
+
envVar(key: string): string;
|
|
26
|
+
getenv(key: string): string | undefined;
|
|
27
|
+
}
|
package/dist/product.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The launcher using camoucore, and the engine it drives.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript twin of python/src/camoucore/product.py. Every engine-specific
|
|
5
|
+
* choice in the core reads these; core code never names a launcher.
|
|
6
|
+
*/
|
|
7
|
+
import { userCacheDir } from "./host.js";
|
|
8
|
+
export const FIREFOX = { name: "firefox", virtualScreen: "1x1x24" };
|
|
9
|
+
export const CHROMIUM = {
|
|
10
|
+
name: "chromium",
|
|
11
|
+
virtualScreen: "3840x2160x24",
|
|
12
|
+
};
|
|
13
|
+
export class Product {
|
|
14
|
+
name;
|
|
15
|
+
title;
|
|
16
|
+
engine;
|
|
17
|
+
constructor(
|
|
18
|
+
/** The package and cache name: "camoufox", "camouwolf". */
|
|
19
|
+
name,
|
|
20
|
+
/** The name in messages: "Camoufox", "Camouwolf". */
|
|
21
|
+
title, engine) {
|
|
22
|
+
this.name = name;
|
|
23
|
+
this.title = title;
|
|
24
|
+
this.engine = engine;
|
|
25
|
+
}
|
|
26
|
+
get cacheDir() {
|
|
27
|
+
return userCacheDir(this.name);
|
|
28
|
+
}
|
|
29
|
+
/** This launcher's name for an environment variable: CAMOUWOLF_<key>. */
|
|
30
|
+
envVar(key) {
|
|
31
|
+
return `${this.name.toUpperCase()}_${key}`;
|
|
32
|
+
}
|
|
33
|
+
getenv(key) {
|
|
34
|
+
return process.env[this.envVar(key)];
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A minimal virtual display implementation for Linux.
|
|
3
|
+
*
|
|
4
|
+
* TypeScript twin of python/src/camoucore/virtdisplay.py.
|
|
5
|
+
*/
|
|
6
|
+
import { type ChildProcess } from "node:child_process";
|
|
7
|
+
import type { Product } from "./product.js";
|
|
8
|
+
/**
|
|
9
|
+
* Xvfb's screen for headless="virtual" comes from the engine (Product.engine)
|
|
10
|
+
* until the launcher fits it to the identity. <LAUNCHER>_VIRTUAL_DISPLAY_SIZE=
|
|
11
|
+
* "<width>x<height>[x<depth>]" fixes the size instead, and the identity's
|
|
12
|
+
* screen is then kept within it.
|
|
13
|
+
*/
|
|
14
|
+
export declare const SCREEN_KEY = "VIRTUAL_DISPLAY_SIZE";
|
|
15
|
+
/**
|
|
16
|
+
* The Composite extension stays disabled (Xvfb's `-extension COMPOSITE`);
|
|
17
|
+
* setting <LAUNCHER>_VIRTUAL_DISPLAY_COMPOSITE to 1 enables it.
|
|
18
|
+
*/
|
|
19
|
+
export declare const COMPOSITE_KEY = "VIRTUAL_DISPLAY_COMPOSITE";
|
|
20
|
+
export declare class VirtualDisplay {
|
|
21
|
+
readonly product: Product;
|
|
22
|
+
debug: boolean;
|
|
23
|
+
screen: string;
|
|
24
|
+
/** A size the caller chose; fit() leaves it alone. */
|
|
25
|
+
fixed: boolean;
|
|
26
|
+
composite: boolean;
|
|
27
|
+
proc: ChildProcess | null;
|
|
28
|
+
protected _display: number | null;
|
|
29
|
+
/** What get() calls the server in its errors. */
|
|
30
|
+
protected serverName: string;
|
|
31
|
+
constructor(product: Product, debug?: boolean, screen?: string, composite?: boolean);
|
|
32
|
+
/** The display's width and height in pixels. */
|
|
33
|
+
get size(): [number, number];
|
|
34
|
+
/**
|
|
35
|
+
* Size a display that is not yet started to `width` x `height` pixels,
|
|
36
|
+
* unless its size was fixed.
|
|
37
|
+
*/
|
|
38
|
+
fit(width: number, height: number): void;
|
|
39
|
+
get xvfbArgs(): string[];
|
|
40
|
+
get xvfbPath(): string;
|
|
41
|
+
get setprivPath(): string;
|
|
42
|
+
/** The error get() raises when the server fails. */
|
|
43
|
+
protected error(message: string): Error;
|
|
44
|
+
/**
|
|
45
|
+
* What execs the server. setpriv's parent-death signal stops Xvfb when this
|
|
46
|
+
* process dies without reaching kill(), even by SIGKILL; SIGTERM lets Xvfb
|
|
47
|
+
* remove its own lock and socket. See xvfb-dies-with-its-launcher in
|
|
48
|
+
* ci/tribal-rules.yml.
|
|
49
|
+
*/
|
|
50
|
+
protected wrapper(): string[];
|
|
51
|
+
/** The server's argv, less -displayfd, which get() adds. */
|
|
52
|
+
protected command(): string[];
|
|
53
|
+
protected serverEnv(): NodeJS.ProcessEnv;
|
|
54
|
+
/** Called once the server has reported its display. */
|
|
55
|
+
protected ready(): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Spawn the server (if it isn't already running) and return its ":N" display.
|
|
58
|
+
*
|
|
59
|
+
* Uses `-displayfd` so the server itself picks a free display number
|
|
60
|
+
* atomically and reports it back, avoiding userspace races. Python's
|
|
61
|
+
* `pass_fds` keeps the fd at its parent number; Node's `stdio` array
|
|
62
|
+
* renumbers extra pipes from 3 upward, so we hand the server fd 3 and read
|
|
63
|
+
* the pipe at index 3.
|
|
64
|
+
*/
|
|
65
|
+
get(): Promise<string>;
|
|
66
|
+
private readDisplayNumber;
|
|
67
|
+
/**
|
|
68
|
+
* Stop Xvfb if it is running, and remove its lock and socket either way: a
|
|
69
|
+
* killed Xvfb leaves its socket behind, and every stranded one pushes
|
|
70
|
+
* -displayfd's next display number higher.
|
|
71
|
+
*/
|
|
72
|
+
kill(): void;
|
|
73
|
+
static assertLinux(): void;
|
|
74
|
+
}
|