Simplify waitFor code (#92)

This commit is contained in:
Pavel Feldman 2017-07-18 12:16:19 -07:00 committed by Andrey Lushnikov
parent 5ca92ffb71
commit bef9982687

View File

@ -178,25 +178,28 @@ class FrameManager extends EventEmitter {
* @return {!Promise<undefined>}
*/
async _waitForInFrame(selector, frame) {
let code = selector => {
let promise = new Promise(fulfill => {
if (document.querySelector(selector)) {
fulfill();
return;
}
new MutationObserver((mutations, observer) => {
function code(selector) {
if (document.querySelector(selector))
return Promise.resolve();
let callback;
const result = new Promise(fulfill => callback = fulfill);
const mo = new MutationObserver((mutations, observer) => {
if (document.querySelector(selector)) {
observer.disconnect();
fulfill();
callback();
return;
}
}).observe(document.documentElement, {
});
mo.observe(document.documentElement, {
childList: true,
subtree: true
});
});
return promise;
};
return result;
}
let contextId = undefined;
if (!frame.isMainFrame()) {
contextId = this._frameIdToExecutionContextId.get(frame._id);