UNPKG

@fpjs-incubator/broyster

Version:
73 lines (72 loc) 2.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.OptionsBuilder = void 0; const edge = require("selenium-webdriver/edge"); const chrome = require("selenium-webdriver/chrome"); const safari = require("selenium-webdriver/safari"); const firefox = require("selenium-webdriver/firefox"); const arguments_1 = require("./arguments"); class OptionsBuilder { static create(browserName, rawArgs = []) { const args = this.mapArguments(browserName, rawArgs); let opts; switch ((browserName || '').toLowerCase()) { case 'chrome': case 'samsung': opts = new chrome.Options().addArguments(...args); break; case 'firefox': opts = new firefox.Options().addArguments(...args); break; case 'safari': { // no args allowed? opts = new safari.Options(); break; } case 'edge': { opts = new edge.Options().addArguments(...args); break; } default: throw new Error(`Unknown or unsupported browser: ${JSON.stringify(browserName)}`); } return opts.setAcceptInsecureCerts(true); } static createSafariArguments(args) { return this.mapArguments('safari', args); } static mapArguments(browserName, args) { let argMap = {}; switch ((browserName || '').toLowerCase()) { case 'chrome': case 'edge': case 'samsung': argMap = chromiumArgs; break; case 'firefox': argMap = firefoxArgs; break; case 'safari': argMap = safariArgs; } return args.map((arg) => { var _a; const canonicalArg = arg.split('-').join('').trim(); return (_a = argMap[canonicalArg]) !== null && _a !== void 0 ? _a : arg; }); } } exports.OptionsBuilder = OptionsBuilder; const chromiumArgs = { [arguments_1.Arguments.MobileUserAgent]: '-use-mobile-user-agent', [arguments_1.Arguments.Incognito]: '--incognito', [arguments_1.Arguments.Headless]: 'headless', }; const firefoxArgs = { [arguments_1.Arguments.MobileUserAgent]: '-use-mobile-user-agent', [arguments_1.Arguments.Incognito]: '-private', [arguments_1.Arguments.Headless]: '-headless', }; const safariArgs = { [arguments_1.Arguments.MobileUserAgent]: '-use-mobile-user-agent', };