arn-browser 0.0.2 → 0.0.3

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.
Files changed (41) hide show
  1. package/dist/__main__.d.ts +2 -0
  2. package/dist/__main__.js +127 -0
  3. package/dist/__version__.d.ts +11 -0
  4. package/dist/__version__.js +16 -0
  5. package/dist/addons.d.ts +17 -0
  6. package/dist/addons.js +70 -0
  7. package/dist/data-files/territoryInfo.xml +2024 -0
  8. package/dist/data-files/webgl_data.db +0 -0
  9. package/dist/exceptions.d.ts +76 -0
  10. package/dist/exceptions.js +153 -0
  11. package/dist/fingerprints.d.ts +4 -0
  12. package/dist/fingerprints.js +82 -0
  13. package/dist/index.d.ts +3 -0
  14. package/dist/index.js +3 -0
  15. package/dist/ip.d.ts +25 -0
  16. package/dist/ip.js +90 -0
  17. package/dist/locale.d.ts +26 -0
  18. package/dist/locale.js +280 -0
  19. package/dist/mappings/browserforge.config.d.ts +47 -0
  20. package/dist/mappings/browserforge.config.js +72 -0
  21. package/dist/mappings/fonts.config.d.ts +6 -0
  22. package/dist/mappings/fonts.config.js +822 -0
  23. package/dist/mappings/warnings.config.d.ts +16 -0
  24. package/dist/mappings/warnings.config.js +28 -0
  25. package/dist/pkgman.d.ts +62 -0
  26. package/dist/pkgman.js +347 -0
  27. package/dist/server.d.ts +6 -0
  28. package/dist/server.js +9 -0
  29. package/dist/sync_api.d.ts +7 -0
  30. package/dist/sync_api.js +27 -0
  31. package/dist/utils.d.ts +88 -0
  32. package/dist/utils.js +500 -0
  33. package/dist/virtdisplay.d.ts +20 -0
  34. package/dist/virtdisplay.js +123 -0
  35. package/dist/warnings.d.ts +4 -0
  36. package/dist/warnings.js +30 -0
  37. package/dist/webgl/db-compat.d.ts +9 -0
  38. package/dist/webgl/db-compat.js +44 -0
  39. package/dist/webgl/sample.d.ts +19 -0
  40. package/dist/webgl/sample.js +85 -0
  41. package/package.json +2 -1
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,127 @@
1
+ #!/usr/bin/env node
2
+ import { existsSync, rmSync } from "node:fs";
3
+ import { Command } from "commander";
4
+ import { DefaultAddons, maybeDownloadAddons } from "./addons.js";
5
+ import { ALLOW_GEOIP, downloadMMDB, removeMMDB } from "./locale.js";
6
+ import { CamoufoxFetcher, INSTALL_DIR, installedVerStr } from "./pkgman.js";
7
+ import { launchServer } from "./server.js";
8
+ import { Camoufox } from "./sync_api.js";
9
+ import { getAsBooleanFromENV } from "./utils.js";
10
+ class CamoufoxUpdate extends CamoufoxFetcher {
11
+ currentVerStr;
12
+ constructor() {
13
+ super();
14
+ this.currentVerStr = null;
15
+ try {
16
+ this.currentVerStr = installedVerStr();
17
+ }
18
+ catch (error) {
19
+ if (error instanceof Error && error.name === "FileNotFoundError") {
20
+ this.currentVerStr = null;
21
+ }
22
+ else {
23
+ throw error;
24
+ }
25
+ }
26
+ }
27
+ static async create() {
28
+ const updater = new CamoufoxUpdate();
29
+ await updater.init();
30
+ return updater;
31
+ }
32
+ isUpdateNeeded() {
33
+ if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
34
+ console.log("Skipping browser download / update check due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
35
+ return false;
36
+ }
37
+ return this.currentVerStr === null || this.currentVerStr !== this.verstr;
38
+ }
39
+ async update() {
40
+ if (!this.isUpdateNeeded()) {
41
+ console.log("Camoufox binaries up to date!");
42
+ console.log(`Current version: v${this.currentVerStr}`);
43
+ return;
44
+ }
45
+ if (this.currentVerStr !== null) {
46
+ console.log(`Updating Camoufox binaries from v${this.currentVerStr} => v${this.verstr}`, "yellow");
47
+ }
48
+ else {
49
+ console.log(`Fetching Camoufox binaries...`);
50
+ }
51
+ await this.install();
52
+ }
53
+ async cleanup() {
54
+ if (!existsSync(INSTALL_DIR)) {
55
+ return false;
56
+ }
57
+ await rmSync(INSTALL_DIR, { recursive: true, force: true });
58
+ console.log("Camoufox binaries removed!");
59
+ return true;
60
+ }
61
+ }
62
+ const program = new Command();
63
+ program.command("fetch").action(async () => {
64
+ const updater = await CamoufoxUpdate.create();
65
+ await updater.update();
66
+ if (ALLOW_GEOIP) {
67
+ downloadMMDB();
68
+ }
69
+ maybeDownloadAddons(DefaultAddons);
70
+ });
71
+ program.command("remove").action(async () => {
72
+ const updater = await CamoufoxUpdate.create();
73
+ if (!(await updater.cleanup())) {
74
+ console.log("Camoufox binaries not found!", "red");
75
+ }
76
+ removeMMDB();
77
+ });
78
+ program
79
+ .command("test")
80
+ .argument("[url]", "URL to open", null)
81
+ .action(async (url) => {
82
+ const browser = await Camoufox({
83
+ headless: false,
84
+ env: process.env,
85
+ config: { showcursor: true },
86
+ humanize: 0.5,
87
+ geoip: true,
88
+ });
89
+ const page = await browser.newPage();
90
+ if (url) {
91
+ await page.goto(url);
92
+ }
93
+ await page.pause();
94
+ });
95
+ program.command("server").action(async () => {
96
+ const server = await launchServer({});
97
+ console.log(`Camoufox server started at ${server.wsEndpoint()}`);
98
+ console.log();
99
+ console.log(`You can connect to it using Playwright's BrowserType.connect() method.`);
100
+ console.log(`To stop the server, press Ctrl+C or close this terminal.`);
101
+ });
102
+ program.command("path").action(() => {
103
+ console.log(INSTALL_DIR);
104
+ });
105
+ program.command("version").action(async () => {
106
+ try {
107
+ const pkgVersion = require("pkg-version");
108
+ console.log(`Pip package:\tv${pkgVersion("camoufox")}`);
109
+ }
110
+ catch (_error) {
111
+ console.log("Pip package:\tNot installed!", "red");
112
+ }
113
+ const updater = await CamoufoxUpdate.create();
114
+ const binVer = updater.currentVerStr;
115
+ if (!binVer) {
116
+ console.log("Camoufox:\tNot downloaded!", "red");
117
+ return;
118
+ }
119
+ console.log(`Camoufox:\tv${binVer} `, "green", false);
120
+ if (updater.isUpdateNeeded()) {
121
+ console.log(`(Latest supported: v${updater.verstr})`, "red");
122
+ }
123
+ else {
124
+ console.log("(Up to date!)", "yellow");
125
+ }
126
+ });
127
+ program.parse(process.argv);
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Camoufox version constants.
3
+ */
4
+ export declare class CONSTRAINTS {
5
+ /**
6
+ * The minimum and maximum supported versions of the Camoufox browser.
7
+ */
8
+ static readonly MIN_VERSION: string;
9
+ static readonly MAX_VERSION: string;
10
+ static asRange(): string;
11
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Camoufox version constants.
3
+ */
4
+ export class CONSTRAINTS {
5
+ /**
6
+ * The minimum and maximum supported versions of the Camoufox browser.
7
+ */
8
+ static MIN_VERSION = "beta.19";
9
+ static MAX_VERSION = "1";
10
+ static asRange() {
11
+ /**
12
+ * Returns the version range as a string.
13
+ */
14
+ return `>=${CONSTRAINTS.MIN_VERSION}, <${CONSTRAINTS.MAX_VERSION}`;
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ export declare const DefaultAddons: {
2
+ /**
3
+ * Default addons to be downloaded
4
+ */
5
+ UBO: string;
6
+ };
7
+ export declare function confirmPaths(paths: string[]): void;
8
+ export declare function addDefaultAddons(_addonsList: string[], _excludeList?: (keyof typeof DefaultAddons)[]): void;
9
+ /**
10
+ * Downloads and extracts an addon from a given URL to a specified path
11
+ */
12
+ export declare function downloadAndExtract(url: string, extractPath: string, name: string): Promise<void>;
13
+ /**
14
+ * Downloads and extracts addons from a given dictionary to a specified list
15
+ * Skips downloading if the addon is already downloaded
16
+ */
17
+ export declare function maybeDownloadAddons(addons: Record<string, string>, addonsList?: string[]): void;
package/dist/addons.js ADDED
@@ -0,0 +1,70 @@
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 function addDefaultAddons(_addonsList, _excludeList = []) {
26
+ // TODO - enable addons
27
+ /**
28
+ * Adds default addons, minus any specified in excludeList, to addonsList
29
+ */
30
+ // const addons = Object.values(DefaultAddons).filter(addon => !excludeList.includes(addon as keyof typeof DefaultAddons));
31
+ // maybeDownloadAddons(addons, addonsList);
32
+ }
33
+ /**
34
+ * Downloads and extracts an addon from a given URL to a specified path
35
+ */
36
+ export async function downloadAndExtract(url, extractPath, name) {
37
+ const buffer = await webdl(url, `Downloading addon (${name})`, false);
38
+ unzip(buffer, extractPath, `Extracting addon (${name})`, false);
39
+ }
40
+ /**
41
+ * Returns a path to the addon
42
+ */
43
+ function getAddonPath(addonName) {
44
+ return getPath(join("addons", addonName));
45
+ }
46
+ /**
47
+ * Downloads and extracts addons from a given dictionary to a specified list
48
+ * Skips downloading if the addon is already downloaded
49
+ */
50
+ export function maybeDownloadAddons(addons, addonsList = []) {
51
+ if (getAsBooleanFromENV("PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD", false)) {
52
+ console.log("Skipping addon download due to PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD set!");
53
+ return;
54
+ }
55
+ for (const addonName in addons) {
56
+ const addonPath = getAddonPath(addonName);
57
+ if (fs.existsSync(addonPath)) {
58
+ addonsList.push(addonPath);
59
+ continue;
60
+ }
61
+ try {
62
+ fs.mkdirSync(addonPath, { recursive: true });
63
+ downloadAndExtract(addons[addonName], addonPath, addonName);
64
+ addonsList.push(addonPath);
65
+ }
66
+ catch (e) {
67
+ console.error(`Failed to download and extract ${addonName}: ${e}`);
68
+ }
69
+ }
70
+ }