diff --git a/lib/Page.js b/lib/Page.js index 9e52fd41082..2499c4972d7 100644 --- a/lib/Page.js +++ b/lib/Page.js @@ -87,8 +87,8 @@ class Page extends EventEmitter { * @return {!Promise} */ async injectFile(filePath) { - var scriptContent = fs.readFileSync(filePath, 'utf8'); - await this.evaluate(scriptContent); + var code = fs.readFileSync(filePath, 'utf8'); + await helpers.evaluateText(this._client, code, false /* awaitPromise */); } /** diff --git a/lib/helpers.js b/lib/helpers.js index d7a19c1ce29..f71c98b4db6 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -54,8 +54,18 @@ var helpers = module.exports = { */ evaluate: function(client, fun, args, awaitPromise, sourceURL) { var code = helpers.evaluationString(fun, args, awaitPromise, sourceURL); + return helpers.evaluateText(client, code, awaitPromise); + }, + + /** + * @param {!CDP} client + * @param {string} text + * @param {boolean} awaitPromise + * @return {!Promise} + */ + evaluateText: function(client, text, awaitPromise) { return client.send('Runtime.evaluate', { - expression: code, + expression: text, awaitPromise: awaitPromise, returnByValue: true });