diff --git a/lib/Page.js b/lib/Page.js index 1fb125348e8..b03049a9b6c 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -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 diff --git a/phantomjs/WebPage.js b/phantomjs/WebPage.js index 63ddf09e5d6..77e7c9bad6d 100644 --- a/phantomjs/WebPage.js +++ b/phantomjs/WebPage.js @@ -84,7 +84,7 @@ class WebPage { * @param {function()} callback */ includeJs(url, callback) { - this._page.addScript(url).then(callback); + this._page.addScriptTag(url).then(callback); } /** @@ -116,8 +116,7 @@ class WebPage { filePath = path.resolve(this.libraryPath, filePath); if (!fs.existsSync(filePath)) return; - var code = fs.readFileSync(filePath, 'utf8'); - this.evaluate(code); + await(this._page.injectFile(filePath)); } /**