Don't ever enable DOM domain. (#145)

This patchs makes sure DOM domain is never enabled. The reasoning behind this is that
DOM domain is heavy-weight: it generates a lot of traffic over the protocol.

Drive-by: use Page.addScriptToEvaluateOnNewDocument instead of Page.addScriptToEvaluateOnLoad
This commit is contained in:
Pavel Feldman 2017-07-26 15:19:43 -07:00 committed by Andrey Lushnikov
parent 7a482c5697
commit 5068185d03

View File

@ -139,7 +139,7 @@ class Page extends EventEmitter {
this._inPageCallbacks[name] = callback;
let expression = helper.evaluationString(inPageCallback, name);
await this._client.send('Page.addScriptToEvaluateOnLoad', { scriptSource: expression });
await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source: expression });
await this._client.send('Runtime.evaluate', { expression, returnByValue: true });
function inPageCallback(callbackName) {
@ -350,8 +350,8 @@ class Page extends EventEmitter {
* @return {!Promise}
*/
async evaluateOnNewDocument(pageFunction, ...args) {
let scriptSource = helper.evaluationString(pageFunction, ...args);
await this._client.send('Page.addScriptToEvaluateOnLoad', { scriptSource });
let source = helper.evaluationString(pageFunction, ...args);
await this._client.send('Page.addScriptToEvaluateOnNewDocument', { source });
}
/**
@ -498,21 +498,6 @@ class Page extends EventEmitter {
await this._client.dispose();
}
/**
* @param {string} selector
* @return {!Promise<number>}
*/
async _querySelector(selector) {
let {root} = await this._client.send('DOM.getDocument', { depth: 1 });
let {nodeId} = await this._client.send('DOM.querySelector', {
nodeId: root.nodeId,
selector
});
if (!nodeId)
throw new Error('No node found for selector: ' + selector);
return nodeId;
}
/**
* @return {!Mouse}
*/
@ -590,12 +575,12 @@ class Page extends EventEmitter {
* @return {!Promise}
*/
async uploadFile(selector, ...filePaths) {
try {
const nodeId = await this._querySelector(selector);
await this._client.send('DOM.setFileInputFiles', { nodeId, files: filePaths });
} finally {
await this._client.send('DOM.disable');
}
let expression = helper.evaluationString(selector => document.querySelector(selector), selector);
const {result} = await this._client.send('Runtime.evaluate', { expression });
if (!result)
return;
const objectId = result.objectId;
return this._client.send('DOM.setFileInputFiles', { objectId, files: filePaths });
}
/**