mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix implementation of Page.injectFile method
This commit is contained in:
parent
68a24b7336
commit
58ad5dd823
@ -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 */);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -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
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user