(browser = process.env.BROWSER || 'chrome', options = {version: process.env.BVER})
| 48 | } |
| 49 | |
| 50 | async function buildDriver(browser = process.env.BROWSER || 'chrome', options = {version: process.env.BVER}) { |
| 51 | const version = mapVersion(browser, options.version); |
| 52 | const platform = puppeteerBrowsers.detectBrowserPlatform(); |
| 53 | |
| 54 | const buildId = await download(browser, version || 'stable', |
| 55 | cacheDir, platform); |
| 56 | |
| 57 | // Chrome options. |
| 58 | const chromeOptions = new chrome.Options() |
| 59 | .addArguments('allow-insecure-localhost') |
| 60 | .addArguments('use-fake-device-for-media-stream') |
| 61 | .addArguments('allow-file-access-from-files'); |
| 62 | if (options.chromeFlags) { |
| 63 | options.chromeFlags.forEach((flag) => chromeOptions.addArguments(flag)); |
| 64 | } |
| 65 | if (options.chromepath) { |
| 66 | chromeOptions.setChromeBinaryPath(options.chromepath); |
| 67 | } else { |
| 68 | chromeOptions.setChromeBinaryPath(puppeteerBrowsers |
| 69 | .computeExecutablePath({browser, buildId, cacheDir, platform})); |
| 70 | } |
| 71 | |
| 72 | if (!options.devices || options.headless) { |
| 73 | // GUM doesn't work in headless mode so we need this. See |
| 74 | // https://bugs.chromium.org/p/chromium/issues/detail?id=776649 |
| 75 | chromeOptions.addArguments('use-fake-ui-for-media-stream'); |
| 76 | } else { |
| 77 | // see https://bugs.chromium.org/p/chromium/issues/detail?id=459532#c22 |
| 78 | const domain = 'https://' + (options.devices.domain || 'localhost') + ':' + (options.devices.port || 443) + ',*'; |
| 79 | const exceptions = { |
| 80 | media_stream_mic: {}, |
| 81 | media_stream_camera: {}, |
| 82 | }; |
| 83 | |
| 84 | exceptions.media_stream_mic[domain] = { |
| 85 | last_used: Date.now(), |
| 86 | setting: options.devices.audio ? 1 : 2 // 0: ask, 1: allow, 2: denied |
| 87 | }; |
| 88 | exceptions.media_stream_camera[domain] = { |
| 89 | last_used: Date.now(), |
| 90 | setting: options.devices.video ? 1 : 2 |
| 91 | }; |
| 92 | |
| 93 | chromeOptions.setUserPreferences({ |
| 94 | profile: { |
| 95 | content_settings: { |
| 96 | exceptions: exceptions |
| 97 | } |
| 98 | } |
| 99 | }); |
| 100 | } |
| 101 | |
| 102 | // Safari options. |
| 103 | const safariOptions = new safari.Options(); |
| 104 | safariOptions.setTechnologyPreview(version === 'unstable'); |
| 105 | |
| 106 | // Firefox options. |
| 107 | const firefoxOptions = new firefox.Options(); |
no test coverage detected