Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(tests): re-verify iframe context after switchToIFrame() before trusting it

damencho684a339b69c2
diff --git a/tests/helpers/Participant.ts b/tests/helpers/Participant.ts
index 5c4b7703dc..3afa3679a1 100644
--- a/tests/helpers/Participant.ts
+++ b/tests/helpers/Participant.ts
@@ -825,8 +825,35 @@ export class Participant {
}
);
- await this.driver.switchFrame(iframe);
- this._inMainFrame = false;
+ const MAX_ATTEMPTS = 3;
+
+ for (let attempt = 1; attempt <= MAX_ATTEMPTS; attempt++) {
+ // Re-select the iframe right before switching rather than reusing the handle fetched above: the
+ // wait for jitsiAPI.test can itself take up to 30s, and switchFrame() pins whatever browsing
+ // context the handle resolves to at that moment, so a stale handle reintroduces the same class of
+ // bug the wait above exists to avoid.
+ await this.driver.switchFrame(this.driver.$('iframe'));
+ this._inMainFrame = false;
+
+ // A switch can still land on a context that is gone or about to be replaced a second time (e.g. an
+ // internal redirect inside the app), which looks identical from here: no response, no error. Confirm
+ // the context is actually alive before trusting it, instead of finding out via some later, unrelated
+ // timeout.
+ const alive = await this.execute(() => document.readyState === 'complete')
+ .catch(() => false);
+
+ if (alive) {
+ return;
+ }
+
+ this._inMainFrame = true;
+ await this.driver.switchFrame(null);
+
+ if (attempt === MAX_ATTEMPTS) {
+ throw new Error(`Switched into a dead iframe context for ${this._name} after ${
+ MAX_ATTEMPTS} attempts.`);
+ }
+ }
}
/**