mirror of
https://github.com/getpaseo/paseo.git
synced 2026-10-24 02:02:42 +00:00
Concurrent locator handlers can wait for a dismiss button another handler removed. Dismiss existing toast DOM at document lifetime, including its open shadow root, without intercepting app actions.
28 lines
1.1 KiB
JavaScript
28 lines
1.1 KiB
JavaScript
/** @param {import('@playwright/test').Page} page */
|
|
export async function installDeveloperToastDismissal(page) {
|
|
// Keep developer chrome out of app actions without pointer/focus changes.
|
|
// Locator handlers can deadlock when concurrent checks dismiss the same toast.
|
|
const install = () => {
|
|
let observedRoot;
|
|
const options = { childList: true, subtree: true };
|
|
const dismiss = () => {
|
|
const toast = document.getElementById("error-toast");
|
|
const root = toast?.shadowRoot ?? toast;
|
|
if (root && root !== observedRoot) {
|
|
observer.disconnect();
|
|
observer.observe(document, options);
|
|
observer.observe(root, options);
|
|
observedRoot = root;
|
|
}
|
|
// Expo's toast root contains dismiss buttons; its overlay has a different ID.
|
|
for (const button of root?.querySelectorAll("button") ?? [])
|
|
button.dispatchEvent(new MouseEvent("click", { bubbles: true }));
|
|
};
|
|
const observer = new MutationObserver(dismiss);
|
|
observer.observe(document, options);
|
|
dismiss();
|
|
};
|
|
await page.addInitScript(install);
|
|
await page.evaluate(install);
|
|
}
|