browser-with-fingerprints
Version:
A plugin that improves the stealth of automation libraries using fingerprints
62 lines (50 loc) • 2.07 kB
JavaScript
const path = require('path');
const DEFAULT_ARGS = [
'--lang=en',
'--no-proxy-server',
'--disable-auto-reload',
'--bas-disable-tab-hook',
'--disk-cache-size=5000000',
'--disable-features=NetworkServiceInProcess2,CookieDeprecationFacilitatedTesting,OptimizationGuideModelDownloading,CookieDeprecationFacilitatedTesting',
];
const IGNORED_ARGS = ['--kiosk', '--headless', '--user-data-dir', '--start-maximized', '--start-fullscreen'];
exports.defaultArgs = ({ args = [], profile = '', devtools = false, headless = !devtools, extensions = [] } = {}) => {
const result = [`--user-data-dir=${profile}`];
const processed = args.reduce(
(args, arg) => {
const [key, value] = arg.split('=');
if (!IGNORED_ARGS.some((value) => arg.includes(value))) {
if (key.includes('disable-extensions-except') || key.includes('load-extension')) {
args.push(`${key}=${extensions.concat(value)}`);
} else {
args.push(arg);
}
}
return args;
},
extensions.length ? [`--load-extension=${extensions}`] : []
);
if (headless) {
result.push('--hide-scrollbars', '--mute-audio');
} else {
result.push('--bas-force-visible-window');
}
return processed.concat(result, DEFAULT_ARGS);
};
exports.getProfilePath = ({ args = [], userDataDir = '' } = {}) => {
if (userDataDir) return path.resolve(userDataDir);
const profilePathArg = args.find((arg) => {
return arg.startsWith('--user-data-dir');
});
return profilePathArg ? profilePathArg.split('=')[1] : '';
};
exports.validateConfig = (type, value, options) => {
if (typeof value !== 'string' || typeof options !== 'object') {
throw new Error(`Invalid arguments for ${type} configuration.`);
}
};
exports.validateLauncher = (launcher) => {
if (launcher == null || typeof launcher !== 'object' || typeof launcher.launch !== 'function') {
throw new Error('Unsupported browser launcher - an object with a "launch" method is expected.');
}
};