mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Simplify waitFor code (#92)
This commit is contained in:
parent
5ca92ffb71
commit
bef9982687
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user