Skip to content

Commit

Permalink
feat: Add support for optional env key to browser launch options
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjduffy committed Sep 8, 2022
1 parent 28b68af commit a29d202
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5480,6 +5480,7 @@ declare namespace Cypress {
extensions: string[]
preferences: { [key: string]: any }
args: string[]
env: { [key: string]: any }
}

interface Dimensions {
Expand Down
1 change: 1 addition & 0 deletions cli/types/tests/plugins-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const pluginConfig2: Cypress.PluginConfig = (on, config) => {
browser.displayName // $ExpectType string
options.extensions // $ExpectType string[]
options.args // $ExpectType string[]
options.env // $ExpectType { [key: string]: any }

console.log('launching browser', browser.displayName)
return options
Expand Down
5 changes: 4 additions & 1 deletion packages/launcher/lib/browsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ export function launch (
debuggingPort: number,
args: string[] = [],
defaultBrowserEnv = {},
launchOptionsEnv = {},
) {
debug('launching browser %o', { browser, url })

Expand All @@ -181,7 +182,9 @@ export function launch (

// allow setting default env vars such as MOZ_HEADLESS_WIDTH
// but only if it's not already set by the environment
const env = Object.assign({}, defaultBrowserEnv, process.env)
const env = Object.assign({}, defaultBrowserEnv, launchOptionsEnv, process.env)

debug('spawning browser with environment %o', { env })

const proc = cp.spawn(browser.path, args, { stdio: ['ignore', 'pipe', 'pipe'], env })

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ export = {
// first allows us to connect the remote interface,
// start video recording and then
// we will load the actual page
const launchedBrowser = await launch(browser, 'about:blank', port, args) as unknown as BrowserInstance & { browserCriClient: BrowserCriClient}
const launchedBrowser = await launch(browser, 'about:blank', port, args, undefined, launchOptions.env) as unknown as BrowserInstance & { browserCriClient: BrowserCriClient}

la(launchedBrowser, 'did not get launched browser instance')

Expand Down
2 changes: 1 addition & 1 deletion packages/server/lib/browsers/firefox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ export async function open (browser: Browser, url: string, options: BrowserLaunc
// user can overwrite this default with these env vars or --height, --width arguments
MOZ_HEADLESS_WIDTH: '1280',
MOZ_HEADLESS_HEIGHT: '721',
})
}, launchOptions.env)

try {
browserCriClient = await firefoxUtil.setup({ automation, extensions: launchOptions.extensions, url, foxdriverPort, marionettePort, remotePort, onError: options.onError, options })
Expand Down
2 changes: 2 additions & 0 deletions packages/server/lib/browsers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ const defaultLaunchOptions: {
preferences: {[key: string]: any}
extensions: string[]
args: string[]
env: { [key: string]: any }
} = {
preferences: {},
extensions: [],
args: [],
env: {},
}

const KNOWN_LAUNCH_OPTION_PROPERTIES = _.keys(defaultLaunchOptions)
Expand Down

0 comments on commit a29d202

Please sign in to comment.