From 699779df7e83ba3529415962bb4a76e0f51aada2 Mon Sep 17 00:00:00 2001 From: Noam Anisfeld <99100497+NoamAnisfeld@users.noreply.github.com> Date: Sun, 18 Feb 2024 16:19:40 +0200 Subject: [PATCH] resolve https://github.com/os-scar/overlay/issues/164 --- src/utils/utils.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/utils/utils.js b/src/utils/utils.js index ea4a993..2cb02ef 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -1,26 +1,26 @@ /** * Waits for element to be rendered in DOM. * @param {string} selector A valid css selector string - * @param {Node} target A DOM Node (which may be an Element) within the DOM tree to watch for changes, or to be the root of a subtree of nodes to be watched. + * @param {Node} [target=document] A DOM Node (which may be an Element) within the DOM tree to watch for changes, or to be the root of a subtree of nodes to be watched. * */ import { SECOND } from '../globals'; const waitElementTimeOot = 10 * SECOND; -const waitForElement = (selector, target) => { +const waitForElement = (selector, target = document) => { return new Promise((resolve, reject) => { setTimeout(() => { reject(new Error('Time out to wait for the element ' + selector)); }, waitElementTimeOot); - if (document.querySelector(selector)) { - return resolve(document.querySelector(selector)); + if (target.querySelector(selector)) { + return resolve(target.querySelector(selector)); } const observer = new MutationObserver(() => { - if (document.querySelector(selector)) { - resolve(document.querySelector(selector)); + if (target.querySelector(selector)) { + resolve(target.querySelector(selector)); observer.disconnect(); } });