Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const webpack = require('webpack');
const webExt = require('web-ext').default;
const config = require('./webpack.config');
const compiler = webpack(config);
const watching = compiler.watch({ aggregateTimeout: 1000 }, (err) => {
/* eslint-disable no-console */
if (err) {
console.log('\nFailed to webpack build');
} else {
console.log('\nweback built');
}
});
webExt.cmd.run({
firefox: process.env.FIREFOX_BINARY,
sourceDir: process.cwd(),
ignoreFiles: process.env.IGNORE_FILES.split(' ').concat('**/*~'),
browserConsole: true,
firefoxProfile: process.env.FIREFOX_PROFILE,
}, {
shouldExitProgram: false,
}).then(runner => runner.registerCleanup(() => watching.close()));
exports.measureFirefox = async function(url, ext) {
let extensionRunners
let browser
if (ext.path) {
// @todo wait for https://github.com/sindresorhus/get-port/pull/28 and than use range for 6000 port
const CDPPort = await getPort()
extensionRunners = await webExt.cmd.run(
{
sourceDir: ext.path,
// comment if connect to default FF
firefox: PP_FF.executablePath(),
args: [`-juggler=${CDPPort}`]
},
{
// These are non CLI related options for each function.
// You need to specify this one so that your NodeJS application
// can continue running after web-ext is finished.
shouldExitProgram: false
}
)
const browserWSEndpoint = `ws://127.0.0.1:${CDPPort}`
browser = await PP_FF.connect({
firefox: firefoxPath,
noReload: true,
sourceDir,
artifactsDir: sourceDir,
startUrl: getOptionsUrl(),
keepProfileChanges,
firefoxProfile,
pref: {
...prefsFromTalos,
'lightweightThemes.selectedThemeID': 'firefox-compact-light@mozilla.org',
'browser.link.open_newwindow': 3,
'dom.min_background_timeout_value': 50,
...this.prefs,
},
};
const runner = await webExt.cmd.run(options, {
getValidatedManifest() {
return {
name: '',
version: '',
};
},
});
this.firefox = runner.firefox;
this.reloadAllExtensions = runner.reloadAllExtensions.bind(runner);
}
exports.sign = function(addonId, apiKey, apiSecret) {
console.log('Running "web-ext sign"...');
return webExt.cmd.sign({
sourceDir: 'src',
artifactsDir: 'dist',
id: addonId,
apiKey: apiKey,
apiSecret: apiSecret,
channel: 'unlisted',
});
};
exports.lint = function() {
console.log('Running web-ext lint...');
return webExt.cmd.lint({
sourceDir: 'src',
}, {
shouldExitProgram: false,
});
};
exports.run = function() {
console.log('Running "web-ext run"...');
return webExt.cmd.run({
sourceDir: path.resolve('src'),
pref: 'javascript.options.strict=false',
});
};
exports.build = function() {
console.log('Running "web-ext build"...');
return webExt.cmd.build({
sourceDir: 'src',
artifactsDir: 'dist',
overwriteDest: true,
});
};
function launchFirefox(cb) {
webext.cmd
.run(
{
sourceDir: distPath,
startUrl: pkg.homepage
},
{
shouldExitProgram: false
}
)
.catch(onError);
logUpdate(
`Firefox should now be open with the ${pkg.name} extension loaded.`
);
cb();
}
function webExtensionRun() {
let dir = process.cwd();
webExt.util.logger.consoleStream.makeVerbose();
webExt.cmd.run({ sourceDir: path.join(dir, "debug") }, { shouldExitProgram: true })
.then((runner) => extensionRunner = runner);
}
function webextRun() {
return webExt.cmd.run({
sourceDir: paths.build.webext
}, {
shouldExitProgram: false,
noInput: true
})
}