fix implementation of Page.injectFile method

This commit is contained in:
Andrey Lushnikov 2017-05-12 14:45:47 -07:00
parent 68a24b7336
commit 58ad5dd823
2 changed files with 13 additions and 3 deletions

View File

@ -87,8 +87,8 @@ class Page extends EventEmitter {
* @return {!Promise} * @return {!Promise}
*/ */
async injectFile(filePath) { async injectFile(filePath) {
var scriptContent = fs.readFileSync(filePath, 'utf8'); var code = fs.readFileSync(filePath, 'utf8');
await this.evaluate(scriptContent); await helpers.evaluateText(this._client, code, false /* awaitPromise */);
} }
/** /**

View File

@ -54,8 +54,18 @@ var helpers = module.exports = {
*/ */
evaluate: function(client, fun, args, awaitPromise, sourceURL) { evaluate: function(client, fun, args, awaitPromise, sourceURL) {
var code = helpers.evaluationString(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<!Object>}
*/
evaluateText: function(client, text, awaitPromise) {
return client.send('Runtime.evaluate', { return client.send('Runtime.evaluate', {
expression: code, expression: text,
awaitPromise: awaitPromise, awaitPromise: awaitPromise,
returnByValue: true returnByValue: true
}); });