From 58ad5dd823cae35bd8d5c42bda038258c0a56d9f Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Fri, 12 May 2017 14:45:47 -0700 Subject: [PATCH] fix implementation of Page.injectFile method --- lib/Page.js | 4 ++-- lib/helpers.js | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) 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 });