UNPKG

@scraping.house/commons

Version:
54 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const playwright_core_1 = require("playwright-core"); const browser_helpers_1 = require("../utils/browser-helpers"); const file_utils_1 = require("../utils/file-utils"); class AbstractModule { constructor({ browser, context, page, authenticatedContextPath }) { this.browser = browser; this.context = context; this.page = page; this.authenticatedContextPath = authenticatedContextPath; } static async initOptions({ browser = 'firefox', launchOptions = {}, contextOptions = undefined, authenticatedContextPath }) { let browserType; let bc; switch (browser) { case 'chrome': browserType = playwright_core_1.chromium; break; case 'firefox': browserType = playwright_core_1.firefox; break; default: browserType = playwright_core_1.webkit; } const b = await browserType.launch(launchOptions); if (authenticatedContextPath !== undefined && authenticatedContextPath !== null && (0, file_utils_1.isFileExists)(authenticatedContextPath)) { bc = await (0, browser_helpers_1.loadBrowserContext)(b, authenticatedContextPath); } else { bc = await b.newContext(contextOptions); } const page = await bc.newPage(); await page.goto(this.BASE_URL); return { browser: b, context: bc, page, authenticatedContextPath }; } /** * Function closes page, context and browser */ async close() { await this.page.close(); await this.context.close(); await this.browser.close(); } } exports.default = AbstractModule; //# sourceMappingURL=abstract-module.js.map