Skip to content

Commit

Permalink
chore: initial work for firefox support
Browse files Browse the repository at this point in the history
  • Loading branch information
lino-levan committed Aug 16, 2023
1 parent 5ca0dd2 commit 9816187
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ async function runCommand(command: Deno.Command) {
}

export interface BrowserOpts {
path?: string;
headless?: boolean;
path?: string;
}

export class Browser {
Expand Down
25 changes: 16 additions & 9 deletions src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { ensureDirSync } from "https://deno.land/[email protected]/fs/ensure_dir.ts";
import { resolve } from "https://deno.land/[email protected]/path/mod.ts";

const REVISION = "1176526";
export const SUPPORTED_VERSIONS = {
chrome: "118.0.5943.0",
} as const;

const HOME_PATH = Deno.build.os === "windows"
? Deno.env.get("USERPROFILE")!
: Deno.env.get("HOME")!;
Expand Down Expand Up @@ -65,14 +68,18 @@ async function decompressArchive(source: string, destination: string) {
* Get path for the binary for this OS. Downloads a browser if none is cached.
*/
export async function getBinary(): Promise<string> {
// TODO(lino-levan): turn this into an argument
const browser = "chrome";
const VERSION = SUPPORTED_VERSIONS[browser];

const config = getCache();

// If the config doesn't have the revision, download it and return that
if (!config[REVISION]) {
if (!config[VERSION]) {
ensureDirSync(BASE_PATH);
const versions = await knownGoodVersions();
const version = versions.versions.filter((val) =>
val.revision === REVISION
val.version === VERSION
)[0];
const download = version.downloads.chrome.filter((val) => {
if (Deno.build.os === "darwin" && Deno.build.arch === "aarch64") {
Expand All @@ -98,19 +105,19 @@ export async function getBinary(): Promise<string> {
"Download failed, please check your internet connection and try again",
);
}
await Deno.writeFile(resolve(BASE_PATH, `raw_${REVISION}.zip`), req.body);
console.log(`Download complete (chrome revision ${REVISION})`);
await Deno.writeFile(resolve(BASE_PATH, `raw_${VERSION}.zip`), req.body);
console.log(`Download complete (${browser} version ${VERSION})`);
await decompressArchive(
resolve(BASE_PATH, `raw_${REVISION}.zip`),
resolve(BASE_PATH, REVISION),
resolve(BASE_PATH, `raw_${VERSION}.zip`),
resolve(BASE_PATH, VERSION),
);

config[REVISION] = resolve(BASE_PATH, REVISION);
config[VERSION] = resolve(BASE_PATH, VERSION);
Deno.writeTextFileSync(CONFIG_PATH, JSON.stringify(config));
}

// It now exists, return the path to the known good binary
const folder = config[REVISION];
const folder = config[VERSION];

if (Deno.build.os === "darwin" && Deno.build.arch === "aarch64") {
return resolve(
Expand Down

0 comments on commit 9816187

Please sign in to comment.