Przeglądaj źródła

added web-driver-executable-path option

Gildas 7 lat temu
rodzic
commit
8dc76cadc9

+ 1 - 1
cli/README.MD

@@ -13,7 +13,7 @@ This is a **work in progress**.
 - [Node.js](https://nodejs.org) must be installed. 
 - By default SingleFile will use Puppeteer to connect to [Chrome/Chromium](https://www.google.com/chrome/). With Puppeteer, Chrome/Chromium must also be installed. 
 - With Selenium WebDriver, you can use [Firefox](https://www.mozilla.org/en/firefox/new/) or Chrome/Chromium. 
-- If you use [Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver) instead of Puppeteer, you must only download the component (e.g. `geckodriver` or `chromedriver`) for your browser and ensure it can be found through the `PATH` environment variable or the current folder.
+- If you use [Selenium WebDriver](https://www.npmjs.com/package/selenium-webdriver) instead of Puppeteer, you must only download the component (e.g. `geckodriver` or `chromedriver`) for your browser and ensure it can be found through the `PATH` environment variable or the current folder. Otherwise you will need to set the `--web-driver-executable-path` option to help SingleFile locating the binary file.
 - It is recommended that the browser binaries can be found through the `PATH` environment variable or the current folder. Otherwise you will need to set the `--browser-executable-path` option to help SingleFile locating the binary file.
 - To convert MAFF files to HTML, you must use specific versions of Firefox and Selenium WebDriver component. You must install respectively [Firefox version 56.0.2](https://ftp.mozilla.org/pub/firefox/releases/56.0.2/) and [Mozilla geckodriver version 0.20.1](https://github.com/mozilla/geckodriver/releases/tag/v0.20.1). See the last example for more info about the options to set.
 

+ 5 - 1
cli/back-ends/webdriver-chrome.js

@@ -21,7 +21,8 @@
  *   Source.
  */
 
-/* global require, exports */
+/* global require, exports, process */
+
 const fs = require("fs");
 
 const chrome = require("selenium-webdriver/chrome");
@@ -67,6 +68,9 @@ exports.getPageData = async options => {
 		if (options.browserExecutablePath) {
 			chromeOptions.setChromeBinaryPath(options.browserExecutablePath);
 		}
+		if (options.webDriverExecutablePath) {
+			process.env["webdriver.chrome.driver"] = options.webDriverExecutablePath;
+		}
 		if (options.browserDisableWebSecurity === undefined || options.browserDisableWebSecurity) {
 			chromeOptions.addArguments("--disable-web-security");
 			chromeOptions.addArguments("--no-pings");

+ 5 - 1
cli/back-ends/webdriver-firefox.js

@@ -21,7 +21,8 @@
  *   Source.
  */
 
-/* global require, exports */
+/* global require, exports, process */
+
 const fs = require("fs");
 
 const firefox = require("selenium-webdriver/firefox");
@@ -66,6 +67,9 @@ exports.getPageData = async options => {
 		if (options.browserExecutablePath) {
 			firefoxOptions.setBinary(options.browserExecutablePath);
 		}
+		if (options.webDriverExecutablePath) {
+			process.env["webdriver.gecko.driver"] = options.webDriverExecutablePath;
+		}
 		const profile = new firefox.Profile();
 		if (options.browserDisableWebSecurity === undefined || options.browserDisableWebSecurity) {
 			profile.addExtension(require.resolve("./extensions/signed/disable_web_security-0.0.3-an+fx.xpi"));

+ 4 - 1
cli/single-file.js

@@ -57,7 +57,8 @@ const args = require("yargs")
 		"remove-alternative-fonts": true,
 		"remove-alternative-medias": true,
 		"remove-alternative-images": true,
-		"save-raw-page": false
+		"save-raw-page": false,
+		"web-driver-executable-path": ""
 	})
 	.options("back-end", { description: "Back-end to use" })
 	.choices("back-end", ["jsdom", "puppeteer", "webdriver-chrome", "webdriver-firefox"])
@@ -111,6 +112,8 @@ const args = require("yargs")
 	.number("remove-alternative-images")
 	.options("save-raw-page", { description: "Save the original page without interpreting it into the browser (puppeteer, webdriver-firefox, webdriver-chrome)" })
 	.number("save-raw-page")
+	.options("web-driver-executable-path", { description: "Path to Selenium WebDriver executable (webdriver-firefox, webdriver-chrome)" })
+	.string("web-driver-executable-path")
 	.argv;
 
 const backEnds = {