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

Commit

Permalink
feat: custom automation (#332)
Browse files Browse the repository at this point in the history
* implement custom automation option

* minor fixes
  • Loading branch information
BeroBurny authored May 31, 2023
1 parent 509e22b commit e25032f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export {
DappeteerLaunchOptions,
MetaMaskOptions,
TransactionOptions,
CustomAutomation,
} from "./types";
export { DappeteerBrowser } from "./browser";
export { DappeteerPage } from "./page";
Expand Down
11 changes: 11 additions & 0 deletions src/setup/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ export async function launch(

if (options.automation) {
switch (options.automation) {
case "custom":
console.warn("Custom automation in use. Proceed at own risk.");
if (!options.customAutomation) {
fs.rmSync(userDataDir, { recursive: true, force: true });
throw new Error("Missing customBootstrap method in options");
}
return await options.customAutomation(
metamaskPath,
userDataDir,
options
);
case "playwright":
return await launchPlaywright(metamaskPath, userDataDir, options);
case "puppeteer":
Expand Down
11 changes: 9 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Path } from "./setup/utils/metaMaskDownloader";
import { InstallStep } from "./snap/install";
import { NotificationItem, NotificationList } from "./snap/types";
import NotificationsEmitter from "./snap/NotificationsEmitter";
import { RECOMMENDED_METAMASK_VERSION } from "./index";
import { DappeteerBrowser, RECOMMENDED_METAMASK_VERSION } from "./index";

export type DappeteerLaunchOptions = {
metaMaskVersion?:
Expand All @@ -19,14 +19,21 @@ export type DappeteerLaunchOptions = {
//install flask (canary) version of metamask.
metaMaskFlask?: boolean;
//fallbacks to installed dependency and prefers playwright if both are installed
automation?: "puppeteer" | "playwright";
automation?: "puppeteer" | "playwright" | "custom";
customAutomation?: CustomAutomation;
headless?: boolean; // default true
puppeteerOptions?: Parameters<typeof puppeteerLaunch>[0];
playwrightOptions?: PlaywrightLaunchOptions;
userDataDir?: string;
key?: string;
};

export type CustomAutomation = (
metamaskPath: string,
userDataDir: string,
options: DappeteerLaunchOptions
) => Promise<DappeteerBrowser>;

declare global {
interface Window {
ethereum: MetaMaskInpageProvider;
Expand Down

0 comments on commit e25032f

Please sign in to comment.