Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
fix: inaccessible under scuttling mode (#308)
Browse files Browse the repository at this point in the history
  • Loading branch information
BeroBurny committed Apr 18, 2023
1 parent 90f45e0 commit a41e6dd
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/setup/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { launchPuppeteer } from "./puppeteer";
import { isNewerVersion } from "./utils/isNewerVersion";
import downloader from "./utils/metaMaskDownloader";
import { getTemporaryUserDataDir } from "./utils/getTemporaryUserDataDir";
import { addKeyToMetaMaskManifest } from "./utils/addKeyToMetaMaskManifest";
import { patchMetaMask } from "./utils/patch";

/**
* Launch Puppeteer chromium instance with MetaMask plugin installed
Expand Down Expand Up @@ -64,7 +64,7 @@ export async function launch(
metamaskPath = options.metaMaskPath;
}

addKeyToMetaMaskManifest(metamaskPath, options.key);
patchMetaMask(metamaskPath, { key: options.key });
const userDataDir = getTemporaryUserDataDir();
if (options.userDataDir)
copyUserDataFiles(path.resolve(options.userDataDir), userDataDir);
Expand Down
13 changes: 13 additions & 0 deletions src/setup/utils/patch/disableScuttleGlobalThis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import path from "path";
import { readFileSync, writeFileSync } from "fs";

export const disableScuttleGlobalThis = (metaMaskPath: string): void => {
const runtimeLavaMoatPath = path.resolve(metaMaskPath, "runtime-lavamoat.js");

const file = readFileSync(runtimeLavaMoatPath, "utf8");
const patchedFile = file.replace(
`"scuttleGlobalThis":true`,
`"scuttleGlobalThis":false`
);
writeFileSync(runtimeLavaMoatPath, patchedFile);
};
14 changes: 14 additions & 0 deletions src/setup/utils/patch/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { addKeyToMetaMaskManifest } from "./addKeyToMetaMaskManifest";
import { disableScuttleGlobalThis } from "./disableScuttleGlobalThis";

interface PatchOptions {
key: string;
}

export const patchMetaMask = (
metamaskPath: string,
options: PatchOptions
): void => {
addKeyToMetaMaskManifest(metamaskPath, options.key);
disableScuttleGlobalThis(metamaskPath);
};

0 comments on commit a41e6dd

Please sign in to comment.