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

Commit

Permalink
chore!: deprecate browser param (#282)
Browse files Browse the repository at this point in the history
* chore!: deprecate `browser` param

* remove `browser` param from tests

* remove `browser` param from test (missed one)

* micro improvements
  • Loading branch information
BeroBurny committed Feb 14, 2023
1 parent 1fb43bd commit a11e1ac
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 36 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ $ yarn add @chainsafe/dappeteer
import dappeteer from '@chainsafe/dappeteer';

async function main() {
const { metaMask, browser } = await dappeteer.bootstrap({
browser: "chrome",
});
const { metaMask, browser } = await dappeteer.bootstrap();

// create a new page and visit your dapp
const dappPage = await browser.newPage();
Expand Down Expand Up @@ -70,7 +68,6 @@ async function main() {

// setup dappateer and install your snap
const { metaMask, snapId, browser } = await dappeteer.initSnapEnv({
browser: "chrome",
snapIdOrLocation: builtSnapDir,
});

Expand Down
2 changes: 0 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ type DappeteerLaunchOptions = {
metaMaskPath?: string;
metaMaskFlask?: boolean;
automation?: "puppeteer" | "playwright";
browser: "chrome";
puppeteerOptions?: Parameters<typeof puppeteerLaunch>[0];
playwrightOptions?: PlaywrightLaunchOptions;
userDataDir?: string;
Expand Down Expand Up @@ -93,7 +92,6 @@ type DappeteerLaunchOptions = {
metaMaskPath?: string;
metaMaskFlask?: boolean;
automation?: "puppeteer" | "playwright";
browser: "chrome";
puppeteerOptions?: Omit<Parameters<typeof puppeteerLaunch>[0], "headless">;
playwrightOptions?: Omit<PlaywrightLaunchOptions, "headless">;
userDataDir?: string;
Expand Down
1 change: 0 additions & 1 deletion src/jest/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { DapeteerJestConfig } from "./global";

export const DAPPETEER_DEFAULT_CONFIG: DappeteerLaunchOptions = {
metaMaskVersion: RECOMMENDED_METAMASK_VERSION,
browser: "chrome",
};

export async function getDappeteerConfig(): Promise<DapeteerJestConfig> {
Expand Down
2 changes: 1 addition & 1 deletion src/setup/launch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { addKeyToMetaMaskManifest } from "./utils/addKeyToMetaMaskManifest";
* Launch Puppeteer chromium instance with MetaMask plugin installed
* */
export async function launch(
options: DappeteerLaunchOptions
options: DappeteerLaunchOptions = {}
): Promise<DappeteerBrowser> {
if (!options.metaMaskVersion && !options.metaMaskPath) {
options.metaMaskVersion = RECOMMENDED_METAMASK_VERSION;
Expand Down
32 changes: 14 additions & 18 deletions src/setup/playwright.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { BrowserContext } from "playwright";
import { DappeteerBrowser } from "../browser";

import { DappeteerLaunchOptions } from "../types";
Expand All @@ -8,23 +7,20 @@ export async function launchPlaywright(
userDataDir: string,
options: DappeteerLaunchOptions
): Promise<DappeteerBrowser> {
let browser: BrowserContext;
if (options.browser === "chrome") {
browser = await (
await import("playwright")
).chromium.launchPersistentContext(userDataDir, {
...(options.playwrightOptions ?? {}),
headless: options.headless,
args: [
"--accept-lang=en",
"--window-size=1920,1080",
`--disable-extensions-except=${metamaskPath}`,
`--load-extension=${metamaskPath}`,
...(options.playwrightOptions?.args || []),
...(options.headless ? ["--headless=new"] : []),
],
});
}
const browser = await (
await import("playwright")
).chromium.launchPersistentContext(userDataDir, {
...(options.playwrightOptions ?? {}),
headless: options.headless,
args: [
"--accept-lang=en",
"--window-size=1920,1080",
`--disable-extensions-except=${metamaskPath}`,
`--load-extension=${metamaskPath}`,
...(options.playwrightOptions?.args || []),
...(options.headless ? ["--headless=new"] : []),
],
});
const { DPlaywrightBrowser } = await import("../playwright");
return new DPlaywrightBrowser(browser, userDataDir, options.metaMaskFlask);
}
1 change: 0 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export type DappeteerLaunchOptions = {
metaMaskFlask?: boolean;
//fallbacks to installed dependency and prefers playwright if both are installed
automation?: "puppeteer" | "playwright";
browser: "chrome";
headless?: boolean; // default true
puppeteerOptions?: Parameters<typeof puppeteerLaunch>[0];
playwrightOptions?: PlaywrightLaunchOptions;
Expand Down
1 change: 0 additions & 1 deletion test/flask/snaps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ describe("should run dappeteer using initSnapEnv method", function () {
({ metaMask, snapId, browser } = await initSnapEnv({
automation:
(process.env.AUTOMATION as "puppeteer" | "playwright") ?? "puppeteer",
browser: "chrome",
snapIdOrLocation: this.snapServers[Snaps.BASE_SNAP],
installationSnapUrl,
}));
Expand Down
1 change: 0 additions & 1 deletion test/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export const mochaHooks = {
password: PASSWORD,
automation:
(process.env.AUTOMATION as "puppeteer" | "playwright") ?? "puppeteer",
browser: "chrome",
metaMaskVersion:
process.env.METAMASK_VERSION || dappeteer.RECOMMENDED_METAMASK_VERSION,
});
Expand Down
1 change: 0 additions & 1 deletion test/global_flask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const mochaHooks = {
password: PASSWORD,
automation:
(process.env.AUTOMATION as "puppeteer" | "playwright") ?? "puppeteer",
browser: "chrome",
metaMaskVersion:
process.env.METAMASK_VERSION || dappeteer.RECOMMENDED_METAMASK_VERSION,
metaMaskFlask: true,
Expand Down
7 changes: 1 addition & 6 deletions test/userData.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe("userData", function () {
});

it("should successfully store user data", async function (this: TestContext) {
const browser = await launch({ automation, browser: "chrome" });
const browser = await launch({ automation });
await setupMetaMask(browser, metaMaskOptions);

// give some pause to store state into files
Expand All @@ -63,7 +63,6 @@ describe("userData", function () {
it("should successfully launch from custom user folder", async function (this: TestContext) {
const browser = await launch({
automation,
browser: "chrome",
userDataDir,
});
const metaMask = await setupBootstrappedMetaMask(
Expand Down Expand Up @@ -95,7 +94,6 @@ describe("userData", function () {
it("should successfully store user data", async function (this: TestContext) {
const browser = await launch({
automation,
browser: "chrome",
metaMaskFlask: true,
});
await setupMetaMask(browser, metaMaskOptions);
Expand All @@ -113,7 +111,6 @@ describe("userData", function () {
it("should successfully launch from custom user folder", async function (this: TestContext) {
const browser = await launch({
automation,
browser: "chrome",
metaMaskFlask: true,
userDataDir,
});
Expand All @@ -137,7 +134,6 @@ describe("userData", function () {
it("should successfully launch project's default MetaMask", async function (this: TestContext) {
const browser = await launch({
automation,
browser: "chrome",
metaMaskFlask: false,
userDataDir: DEFAULT_METAMASK_USERDATA,
});
Expand All @@ -160,7 +156,6 @@ describe("userData", function () {
it("should successfully launch project's default Flask", async function (this: TestContext) {
const browser = await launch({
automation,
browser: "chrome",
metaMaskFlask: true,
userDataDir: DEFAULT_FLASK_USERDATA,
});
Expand Down

0 comments on commit a11e1ac

Please sign in to comment.