From d74c368627d7329bb8cb05f0ba64f969c6c727c8 Mon Sep 17 00:00:00 2001 From: Jia Hao Date: Mon, 25 Jan 2016 23:42:28 +0800 Subject: [PATCH] Add command line flag to make the packaged app ignore certificate errors, fixes #69 --- README.md | 7 +++++++ app/src/main.js | 4 ++++ src/buildApp.js | 8 +++++--- src/cli.js | 1 + src/options.js | 4 +++- 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d3fe258..09e4f61 100644 --- a/README.md +++ b/README.md @@ -185,6 +185,13 @@ By default, nativefier uses a preset user agent string for your OS and masquerad If this flag is passed, it will not override the user agent. +#### [insecure] + +``` +--insecure +``` +Forces the packaged app to ignore certificate errors. + ## How It Works A template app with the appropriate event listeners and callbacks set up is included in the `./app` folder. When the `nativefier` command is executed, this folder is copied to a temporary directory with the appropriate parameters in a configuration file, and is packaged into an app with [Electron Packager](https://github.com/maxogden/electron-packager). diff --git a/app/src/main.js b/app/src/main.js index d7adccf..7cc5f10 100644 --- a/app/src/main.js +++ b/app/src/main.js @@ -20,6 +20,10 @@ var appArgs = JSON.parse(fs.readFileSync(APP_ARGS_FILE_PATH, 'utf8')); var mainWindow; +if (appArgs.insecure) { + app.commandLine.appendSwitch('ignore-certificate-errors'); +} + // do nothing for setDockBadge if not OSX let setDockBadge = () => {}; diff --git a/src/buildApp.js b/src/buildApp.js index 4bb0c27..18c9914 100644 --- a/src/buildApp.js +++ b/src/buildApp.js @@ -48,10 +48,11 @@ function buildApp(options, callback) { options.showMenuBar, options.userAgent, options.honest, + options.insecure, callback); }, (options, callback) => { - copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.counter, options.width, options.height, options.showMenuBar, options.userAgent, (error, tempDirPath) => { + copyPlaceholderApp(options.dir, tmpPath, options.name, options.targetUrl, options.counter, options.width, options.height, options.showMenuBar, options.userAgent, options.insecure, (error, tempDirPath) => { callback(error, tempDirPath, options); }); }, @@ -92,7 +93,7 @@ function buildApp(options, callback) { * @param {string} userAgent * @param {tempDirCallback} callback */ -function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, counter, width, height, showMenuBar, userAgent, callback) { +function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, counter, width, height, showMenuBar, userAgent, insecure, callback) { const loadedPackageJson = packageJson; copy(srcAppDir, tempDir, function(error) { if (error) { @@ -109,7 +110,8 @@ function copyPlaceholderApp(srcAppDir, tempDir, name, targetURL, counter, width, height: height, showMenuBar: showMenuBar, userAgent: userAgent, - nativefierVersion: loadedPackageJson.version + nativefierVersion: loadedPackageJson.version, + insecure: insecure }; fs.writeFileSync(path.join(tempDir, '/nativefier.json'), JSON.stringify(appArgs)); diff --git a/src/cli.js b/src/cli.js index 593a5af..2e5dc72 100755 --- a/src/cli.js +++ b/src/cli.js @@ -28,6 +28,7 @@ if (require.main === module) { .option('-m, --show-menu-bar', 'set menu bar visible, defaults to false') .option('-u, --user-agent ', 'set the user agent string for the app') .option('--honest', 'prevent the nativefied app from changing the user agent string to masquerade as a regular chrome browser') + .option('--insecure', 'ignore certificate related errors') .parse(process.argv); if (!process.argv.slice(2).length) { diff --git a/src/options.js b/src/options.js index 4d26551..3cf3688 100644 --- a/src/options.js +++ b/src/options.js @@ -25,6 +25,7 @@ function optionsFactory(name, showMenuBar = false, userAgent, honest = false, + insecure = false, callback) { targetUrl = normalizeUrl(targetUrl); @@ -62,7 +63,8 @@ function optionsFactory(name, width: width, height: height, showMenuBar: showMenuBar, - userAgent: userAgent + userAgent: userAgent, + insecure: insecure }; if (name && name.length > 0) {