Add support for basic auth in NPM driver

main
Elbert Alias 7 years ago
parent 2ac339156a
commit 0083cf14f1

@ -27,16 +27,19 @@ node index.js [url] [options]
### Options ### Options
``` ```
--password Password to be used for basic HTTP authentication
--proxy Proxy URL, e.g. 'http://user:pass@proxy:8080'
--username Username to be used for basic HTTP authentication
--chunk-size=num Process links in chunks. --chunk-size=num Process links in chunks.
--debug=0|1 Output debug messages. --debug=0|1 Output debug messages.
--delay=ms Wait for ms milliseconds between requests. --delay=ms Wait for ms milliseconds between requests.
--html-max-cols=num Limit the number of HTML characters per line processed.
--html-max-rows=num Limit the number of HTML lines processed.
--max-depth=num Don't analyse pages more than num levels deep. --max-depth=num Don't analyse pages more than num levels deep.
--max-urls=num Exit when num URLs have been analysed. --max-urls=num Exit when num URLs have been analysed.
--max-wait=ms Wait no more than ms milliseconds for page resources to load. --max-wait=ms Wait no more than ms milliseconds for page resources to load.
--recursive=0|1 Follow links on pages (crawler). --recursive=0|1 Follow links on pages (crawler).
--user-agent=str Set the user agent string. --user-agent=str Set the user agent string.
--html-max-cols=num Limit the number of HTML characters per line processed.
--html-max-rows=num Limit the number of HTML lines processed.
``` ```

@ -13,17 +13,19 @@ const extensions = /^([^.]+$|\.(asp|aspx|cgi|htm|html|jsp|php)$)/;
class Driver { class Driver {
constructor(pageUrl, options) { constructor(pageUrl, options) {
this.options = Object.assign({}, { this.options = Object.assign({}, {
password: '',
proxy: null,
username: '',
chunkSize: 5, chunkSize: 5,
debug: false, debug: false,
delay: 500, delay: 500,
htmlMaxCols: 2000,
htmlMaxRows: 3000,
maxDepth: 3, maxDepth: 3,
maxUrls: 10, maxUrls: 10,
maxWait: 5000, maxWait: 5000,
proxy: null,
recursive: false, recursive: false,
userAgent: 'Mozilla/5.0 (compatible; Wappalyzer)', userAgent: 'Mozilla/5.0 (compatible; Wappalyzer)',
htmlMaxCols: 2000,
htmlMaxRows: 3000,
}, options || {}); }, options || {});
this.options.debug = Boolean(+this.options.debug); this.options.debug = Boolean(+this.options.debug);
@ -121,6 +123,11 @@ class Driver {
waitDuration: this.options.maxWait, waitDuration: this.options.maxWait,
}); });
browser.on('authenticate', auth => {
auth.username = this.options.username;
auth.password = this.options.password;
});
this.timer('browser.visit start; url: ' + pageUrl.href, timerScope); this.timer('browser.visit start; url: ' + pageUrl.href, timerScope);
browser.visit(pageUrl.href, () => { browser.visit(pageUrl.href, () => {