SDA-3377 Processing multiple chrome flags provided as installation parameters

This commit is contained in:
Salah Benmoussati 2021-10-27 17:05:53 +02:00
parent e3a5cedd22
commit 071cb939ef
3 changed files with 44 additions and 11 deletions

View File

@ -57,4 +57,6 @@ position:
- openExternal: This allows users to control if the SDA can open an external app. If set to "false", SDA won't be able to open external apps. For example, opening a link from within the SDA in a browser tab. - openExternal: This allows users to control if the SDA can open an external app. If set to "false", SDA won't be able to open external apps. For example, opening a link from within the SDA in a browser tab.
- autoLaunchPath: This allows administrators to set a custom launch path for an app that can bootstrap the SDA. Typically used by administrators who have their own bootstrapped to open other apps like the SDA. - autoLaunchPath: This allows administrators to set a custom launch path for an app that can bootstrap the SDA. Typically used by administrators who have their own bootstrapped to open other apps like the SDA.
- Example can be C:\Program Files\My Bootstrapper\start.exe - Example can be C:\Program Files\My Bootstrapper\start.exe
- chromeFlags: This allows users to set Chromium flags.
- Example can be "--enable-logging --log-file=C:\\Users\\YOUR_USER\\Desktop\\chrome_debug.log"

View File

@ -26,6 +26,11 @@ jest.mock('../src/app/config-handler', () => {
disableThrottling: 'DISABLED', disableThrottling: 'DISABLED',
}; };
}), }),
getGlobalConfigFields: jest.fn(() => {
return {
disableThrottling: 'DISABLED',
};
}),
}, },
}; };
}); });

View File

@ -3,6 +3,8 @@ import { app, session } from 'electron';
import { logger } from '../common/logger'; import { logger } from '../common/logger';
import { CloudConfigDataTypes, config, IConfig } from './config-handler'; import { CloudConfigDataTypes, config, IConfig } from './config-handler';
const CHROME_FLAG_PREFIX = '--';
// Set default flags // Set default flags
logger.info(`chrome-flags: Setting mandatory chrome flags`, { logger.info(`chrome-flags: Setting mandatory chrome flags`, {
flag: { 'ssl-version-fallback-min': 'tls1.2' }, flag: { 'ssl-version-fallback-min': 'tls1.2' },
@ -63,39 +65,45 @@ export const setChromeFlags = () => {
app.commandLine.appendSwitch(key, val); app.commandLine.appendSwitch(key, val);
} }
} }
let cmdArgs = process.argv;
const cmdArgs = process.argv; const { chromeFlags } = config.getGlobalConfigFields(['chromeFlags']) as any;
if (chromeFlags?.length) {
logger.info(
`chrome-flags: found chrome flags in config file: ${chromeFlags}`,
);
const splittedChromeFlags = chromeFlagsSplitter(chromeFlags);
cmdArgs = cmdArgs.concat(splittedChromeFlags);
}
cmdArgs.forEach((arg) => { cmdArgs.forEach((arg) => {
// We need to check if the argument key matches the one // We need to check if the argument key matches the one
// in the special args array and return if it does match // in the special args array and return if it does match
const argSplit = arg.split('='); const argSplit = arg.split('=');
const argKey = argSplit[0]; const argKey = argSplit[0];
const argValue = argSplit[1] && arg.substring(arg.indexOf('=') + 1); const argValue = argSplit[1] && arg.substring(arg.indexOf('=') + 1);
if (arg.startsWith('--') && specialArgs.includes(argKey)) { if (arg.startsWith(CHROME_FLAG_PREFIX) && specialArgs.includes(argKey)) {
return; return;
} }
// All the chrome flags starts with -- // All the chrome flags starts with --
// So, any other arg (like 'electron' or '.') // So, any other arg (like 'electron' or '.')
// need to be skipped // need to be skipped
if (arg.startsWith('--')) { if (arg.startsWith(CHROME_FLAG_PREFIX)) {
// Since chrome takes values after an equals // Since chrome takes values after an equals
// We split the arg and set it either as // We split the arg and set it either as
// just a key, or as a key-value pair // just a key, or as a key-value pair
if (argKey && argValue) { if (argKey && argValue) {
app.commandLine.appendSwitch(argKey.substr(2), argValue); app.commandLine.appendSwitch(argKey.substr(2), argValue);
logger.info(
`chrome-flags: Appended chrome command line switch ${argKey} with value ${argValue}`,
);
} else { } else {
app.commandLine.appendSwitch(argKey); app.commandLine.appendSwitch(argKey);
logger.info(
`chrome-flags: Appended chrome command line switch ${argKey}`,
);
} }
logger.info(
`Appended chrome command line switch ${argKey} with value ${argValue}`,
);
} }
}); });
const { chromeFlags } = config.getConfigFields(['chromeFlags']) as any;
app.commandLine.appendSwitch(chromeFlags);
logger.info(`chrome-flags: Appended chrome command line with ${chromeFlags}`);
}; };
/** /**
@ -116,3 +124,21 @@ export const setSessionProperties = () => {
); );
} }
}; };
/**
* Splits a string of concatenated chrome flags into an array of chrome flags.
* @param flags Chrome flags provided as a string
* @returns An array of chrome flags
*/
const chromeFlagsSplitter = (flags: string) => {
logger.info('chrome-flags: Parsing flags', flags);
const splittedFlags = flags
.split(CHROME_FLAG_PREFIX)
.filter((chromeFlag: string) => chromeFlag.length)
.map(
(filteredFlag: string) =>
`${CHROME_FLAG_PREFIX}${filteredFlag.trimEnd()}`,
);
logger.info('chrome-flags: Parsed flags', splittedFlags);
return splittedFlags;
};