fix(page): use secondary DOMWorld to drive page.select() (#3809)

This patch starts creating secondary DOMWorld for every connected
page and switches `page.select()` to run inside the secondary world.

Fix #3327.
This commit is contained in:
Andrey Lushnikov
2019-01-22 17:55:33 -05:00
committed by GitHub
parent c09835fd70
commit 678b8e85ad
6 changed files with 74 additions and 56 deletions

View File

@@ -44,6 +44,13 @@ class DOMWorld {
this._detached = false;
}
/**
* @return {!Puppeteer.Frame}
*/
frame() {
return this._frame;
}
/**
* @param {?Puppeteer.ExecutionContext} context
*/
@@ -419,28 +426,6 @@ class DOMWorld {
await handle.dispose();
}
/**
* @param {(string|number|Function)} selectorOrFunctionOrTimeout
* @param {!Object=} options
* @param {!Array<*>} args
* @return {!Promise<!Puppeteer.JSHandle>}
*/
waitFor(selectorOrFunctionOrTimeout, options = {}, ...args) {
const xPathPattern = '//';
if (helper.isString(selectorOrFunctionOrTimeout)) {
const string = /** @type {string} */ (selectorOrFunctionOrTimeout);
if (string.startsWith(xPathPattern))
return this.waitForXPath(string, options);
return this.waitForSelector(string, options);
}
if (helper.isNumber(selectorOrFunctionOrTimeout))
return new Promise(fulfill => setTimeout(fulfill, /** @type {number} */ (selectorOrFunctionOrTimeout)));
if (typeof selectorOrFunctionOrTimeout === 'function')
return this.waitForFunction(selectorOrFunctionOrTimeout, options, ...args);
return Promise.reject(new Error('Unsupported target type: ' + (typeof selectorOrFunctionOrTimeout)));
}
/**
* @param {string} selector
* @param {!{visible?: boolean, hidden?: boolean, timeout?: number}=} options