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
```
--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.
--debug=0|1 Output debug messages.
--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-urls=num Exit when num URLs have been analysed.
--max-wait=ms Wait no more than ms milliseconds for page resources to load.
--recursive=0|1 Follow links on pages (crawler).
--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 {
constructor(pageUrl, options) {
this.options = Object.assign({}, {
password: '',
proxy: null,
username: '',
chunkSize: 5,
debug: false,
delay: 500,
htmlMaxCols: 2000,
htmlMaxRows: 3000,
maxDepth: 3,
maxUrls: 10,
maxWait: 5000,
proxy: null,
recursive: false,
userAgent: 'Mozilla/5.0 (compatible; Wappalyzer)',
htmlMaxCols: 2000,
htmlMaxRows: 3000,
}, options || {});
this.options.debug = Boolean(+this.options.debug);
@ -121,6 +123,11 @@ class Driver {
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);
browser.visit(pageUrl.href, () => {