headfox-js 0.1.1
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.md +373 -0
- package/README.md +121 -0
- package/bin/headfox-js.mjs +17 -0
- package/dist/__main__.d.ts +2 -0
- package/dist/__main__.js +131 -0
- package/dist/__version__.d.ts +8 -0
- package/dist/__version__.js +10 -0
- package/dist/addons.d.ts +17 -0
- package/dist/addons.js +74 -0
- package/dist/data-files/territoryInfo.xml +2024 -0
- package/dist/data-files/webgl_data.db +0 -0
- package/dist/exceptions.d.ts +82 -0
- package/dist/exceptions.js +165 -0
- package/dist/fingerprints.d.ts +4 -0
- package/dist/fingerprints.js +82 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/ip.d.ts +25 -0
- package/dist/ip.js +90 -0
- package/dist/locale.d.ts +26 -0
- package/dist/locale.js +285 -0
- package/dist/mappings/browserforge.config.d.ts +47 -0
- package/dist/mappings/browserforge.config.js +72 -0
- package/dist/mappings/fonts.config.d.ts +6 -0
- package/dist/mappings/fonts.config.js +822 -0
- package/dist/mappings/warnings.config.d.ts +16 -0
- package/dist/mappings/warnings.config.js +27 -0
- package/dist/pkgman.d.ts +67 -0
- package/dist/pkgman.js +421 -0
- package/dist/server.d.ts +7 -0
- package/dist/server.js +24 -0
- package/dist/sync_api.d.ts +10 -0
- package/dist/sync_api.js +35 -0
- package/dist/utils.d.ts +109 -0
- package/dist/utils.js +540 -0
- package/dist/virtdisplay.d.ts +20 -0
- package/dist/virtdisplay.js +123 -0
- package/dist/warnings.d.ts +4 -0
- package/dist/warnings.js +33 -0
- package/dist/webgl/sample.d.ts +19 -0
- package/dist/webgl/sample.js +121 -0
- package/package.json +94 -0
package/dist/addons.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { InvalidAddonPath } from "./exceptions.js";
|
|
4
|
+
import { getPath, unzip, webdl } from "./pkgman.js";
|
|
5
|
+
import { getAsBooleanFromENV } from "./utils.js";
|
|
6
|
+
export const DefaultAddons = {
|
|
7
|
+
/**
|
|
8
|
+
* Default addons to be downloaded
|
|
9
|
+
*/
|
|
10
|
+
UBO: "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi",
|
|
11
|
+
};
|
|
12
|
+
export function confirmPaths(paths) {
|
|
13
|
+
/**
|
|
14
|
+
* Confirms that the addon paths are valid
|
|
15
|
+
*/
|
|
16
|
+
for (const path of paths) {
|
|
17
|
+
if (!fs.existsSync(path) || !fs.lstatSync(path).isDirectory()) {
|
|
18
|
+
throw new InvalidAddonPath(path);
|
|
19
|
+
}
|
|
20
|
+
if (!fs.existsSync(join(path, "manifest.json"))) {
|
|
21
|
+
throw new InvalidAddonPath("manifest.json is missing. Addon path must be a path to an extracted addon.");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export async function addDefaultAddons(addonsList, excludeList = []) {
|
|
26
|
+
/**
|
|
27
|
+
* Adds default addons, minus any specified in excludeList, to addonsList
|
|
28
|
+
*/
|
|
29
|
+
const addons = {};
|
|
30
|
+
for (const [name, url] of Object.entries(DefaultAddons)) {
|
|
31
|
+
if (!excludeList.includes(name)) {
|
|
32
|
+
addons[name] = url;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
await maybeDownloadAddons(addons, addonsList);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Downloads and extracts an addon from a given URL to a specified path
|
|
39
|
+
*/
|
|
40
|
+
export async function downloadAndExtract(url, extractPath, name) {
|
|
41
|
+
const buffer = await webdl(url, `Downloading addon (${name})`, false);
|
|
42
|
+
await unzip(buffer, extractPath, `Extracting addon (${name})`, false);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Returns a path to the addon
|
|
46
|
+
*/
|
|
47
|
+
function getAddonPath(addonName) {
|
|
48
|
+
return getPath(join("addons", addonName));
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Downloads and extracts addons from a given dictionary to a specified list
|
|
52
|
+
* Skips downloading if the addon is already downloaded
|
|
53
|
+
*/
|
|
54
|
+
export async function maybeDownloadAddons(addons, addonsList = []) {
|
|
55
|
+
if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
|
|
56
|
+
console.log("Skipping addon download due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
for (const addonName in addons) {
|
|
60
|
+
const addonPath = getAddonPath(addonName);
|
|
61
|
+
if (fs.existsSync(addonPath)) {
|
|
62
|
+
addonsList.push(addonPath);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
fs.mkdirSync(addonPath, { recursive: true });
|
|
67
|
+
await downloadAndExtract(addons[addonName], addonPath, addonName);
|
|
68
|
+
addonsList.push(addonPath);
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
console.error(`Failed to download and extract ${addonName}: ${e}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|