I want to develop a content-script webextension for a particular website, whose document's scripts insert elements into the DOM. I would like my content-script wait for the elements to appear in the DOM so that it can interact with the elements.
I am thinking in line of the Page.WaitForSelector() method that is available in the Puppeteer node.js library. I would like to do something like the following:
const button = await waitForSelector('a[role="click-me"]');
button.click();
const purpose = await waitForSelector('input[data="purpose']');
purpose.innerText = "I want to dump my brain";
waitForSelector has a 2nd timeout parameter with a reasonable default value. It returns a promise which resolves to a HTMLelement when the element appears in the document.body or null on timeout. I would need to develop my webextension iteratively to find the correct selector strings for the waitForSelector's first parameter.
How do I implement waitForSelector?