Introduce Page.injectFile method

With this patch, page has two methods to include javascript:
- Page.addScriptTag(url) which is similar to phantom's includeJs.
- Page.injectFile(filePath) which is similar to phantom's injectJs.
This commit is contained in:
Andrey Lushnikov
2017-05-12 10:19:01 -07:00
parent e991b0e20a
commit 2de672ed1b
2 changed files with 12 additions and 4 deletions

View File

@@ -66,7 +66,7 @@ class Page extends EventEmitter {
* @param {string} url
* @return {!Promise}
*/
async addScript(url) {
async addScriptTag(url) {
return this.evaluateAsync(addScriptTag, url);
/**
@@ -81,6 +81,15 @@ class Page extends EventEmitter {
}
}
/**
* @param {string} filePath
* @return {!Promise}
*/
async injectFile(filePath) {
var scriptContent = fs.readFileSync(filePath, 'utf8');
await this.evaluate(scriptContent);
}
/**
* @param {string} name
* @param {function(?)} callback