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): survive the browser dropping a frame context or element handle

damencho71cedf93cb07
diff --git a/tests/helpers/Participant.ts b/tests/helpers/Participant.ts
index 34c6b5e5ea..5c4b7703dc 100644
--- a/tests/helpers/Participant.ts
+++ b/tests/helpers/Participant.ts
@@ -40,6 +40,18 @@ export const P4 = 'p4';
export const P5 = 'p5';
export const P6 = 'p6';
+/**
+ * How long to wait for a script to return a result, mirroring `connectionRetryTimeout` in the wdio configs.
+ * That setting covers the classic HTTP commands, but a WebDriver BiDi script call goes over the session's
+ * websocket, where a call aimed at a browsing context that has gone away simply never gets a response. That
+ * is worse than slow: wdio's waitUntil arms its own timeout only once a condition has been evaluated, so a
+ * first evaluation that never settles hangs the wait with no error at all, and the test spends its whole
+ * mocha budget before failing with an uninformative "Timeout of 180000ms exceeded". Bounding the call keeps
+ * the failure attributable to the script that got stuck. See also switchToIFrame(), which is where such a
+ * context has been observed being pinned.
+ */
+const EXECUTE_TIMEOUT = 30_000;
+
/**
* Participant.
*/
@@ -143,12 +155,30 @@ export class Participant {
async execute<ReturnValue, InnerArguments extends any[]>(
script: string | ((...innerArgs: InnerArguments) => ReturnValue),
...args: InnerArguments): Promise<ReturnValue> {
+ let timer: ReturnType<typeof setTimeout> | undefined;
+
+ // @ts-ignore
+ const result = this.driver.execute(script, ...args) as Promise<ReturnValue>;
+
+ // The timeout below can win the race, and this promise then settles with nobody waiting on it.
+ // An unhandled rejection would take down the whole worker, so keep it handled.
+ result.catch(() => undefined);
+
try {
- // @ts-ignore
- return await this.driver.execute(script, ...args);
+ return await Promise.race([
+ result,
+ new Promise<ReturnValue>((_, reject) => {
+ timer = setTimeout(
+ () => reject(new Error(
+ `Timeout of ${EXECUTE_TIMEOUT}ms executing a script for ${this._name}.`)),
+ EXECUTE_TIMEOUT);
+ })
+ ]);
} catch (error) {
console.error('An error occurred while trying to execute a script: ', error);
throw error;
+ } finally {
+ clearTimeout(timer);
}
}
@@ -275,31 +305,41 @@ export class Participant {
await this.switchToIFrame();
}
- if (!options.skipPrejoinButtonClick
- // @ts-ignore
- && !Boolean(await this.execute(() => config.prejoinConfig?.enabled === false))) {
+ if (!options.skipPrejoinButtonClick) {
// The prejoin Join button can be in the DOM before conference.init has run and React click
// handlers are mounted (e.g. when driver.url() returns before the page fully loads on a slow
// remote grid, or when the iFrame API wrapper fires onload before the embedded app inits).
- // APP.store is created during conference.init, so gate the click on it to avoid the race.
+ // APP.store is created during conference.init, so gate the click on it to avoid the race. It
+ // also has to come before the `config` probe below, which reads a global the app script
+ // defines. Failed evaluations are retried rather than propagated: this is the first script run
+ // against a freshly loaded page (or, with the iFrame API, a frame just switched into).
await this.driver.waitUntil(
- // @ts-ignore
- () => this.execute(() => typeof APP !== 'undefined' && Boolean(APP.store)),
+ async () => {
+ try {
+ // @ts-ignore
+ return await this.execute(() => typeof APP !== 'undefined' && Boolean(APP.store));
+ } catch (e) {
+ return false;
+ }
+ },
{
timeout: 30_000,
timeoutMsg: `Timeout waiting for Jitsi app to initialize for ${this._name}.`
}
);
- // if prejoin is enabled we want to click the join button
- const p1PreJoinScreen = this.getPreJoinScreen();
+ // @ts-ignore
+ if (!await this.execute(() => config.prejoinConfig?.enabled === false)) {
+ // if prejoin is enabled we want to click the join button
+ const p1PreJoinScreen = this.getPreJoinScreen();
- await p1PreJoinScreen.waitForLoading();
+ await p1PreJoinScreen.waitForLoading();
- const joinButton = p1PreJoinScreen.getJoinButton();
+ const joinButton = p1PreJoinScreen.getJoinButton();
- await joinButton.waitForDisplayed();
- await joinButton.click();
+ await joinButton.waitForDisplayed();
+ await joinButton.click();
+ }
}
if (!options.skipWaitToJoin) {
@@ -767,6 +807,24 @@ export class Participant {
// before switching rather than failing immediately with "iframe doesn't exist" on slower backends.
await iframe.waitForExist({ timeout: 10_000 });
+ // Existing is not enough to switch into it. The iframe is created with its src already set, so the element
+ // is there while its document is still the initial about:blank, and switchFrame() pins whichever browsing
+ // context it finds at that moment - it resolves iframe.contentWindow to a context id and aims every later
+ // BiDi command at that id. The app document then replaces about:blank in a context of its own (the wrapper
+ // page is served from file://, so the app is always cross origin), and a switch that lands in the window in
+ // between leaves every following script call aimed at a context that no longer exists: no response, no
+ // error, and waitUntil cannot time out while its first evaluation is still pending. Waiting for the
+ // wrapper's jitsiAPI.test, which it sets from the External API's onload, puts the switch after the app
+ // document has loaded.
+ await this.driver.waitUntil(
+ // @ts-ignore
+ () => this.execute(() => Boolean(window.jitsiAPI?.test)),
+ {
+ timeout: 30_000,
+ timeoutMsg: `Timeout waiting for the iframe API to load for ${this._name}.`
+ }
+ );
+
await this.driver.switchFrame(iframe);
this._inMainFrame = false;
}
diff --git a/tests/helpers/participants.ts b/tests/helpers/participants.ts
index 5125764a36..4a6c730f25 100644
--- a/tests/helpers/participants.ts
+++ b/tests/helpers/participants.ts
@@ -287,10 +287,31 @@ export async function checkSubject(participant: Participant, subject: string) {
* Expects there was already a video by this participant and screen sharing will be the second video `-v1`.
*/
export async function checkForScreensharingTile(sharer: Participant, observer: Participant, reverse = false) {
- await observer.driver.$(`//span[@id='participant_${await sharer.getEndpointId()}-v1']`).waitForDisplayed({
- timeout: 3_000,
- reverse
- });
+ const selector = `//span[@id='participant_${await sharer.getEndpointId()}-v1']`;
+
+ // Re-runs the selector on every poll, unlike waitForDisplayed(), which keeps checking the element it
+ // matched first. Thumbnails get replaced by React while the wait is running, and losing the matched one
+ // is not something wdio recovers from here: over WebDriver BiDi the node handle is passed to the
+ // visibility check as a script argument, so Chrome rejects it with `invalid argument - Invalid input in
+ // "arguments"/0`, which wdio's refetch-on-stale handling does not recognize as staleness. Every
+ // remaining poll then reuses the dead handle, failing the wait while a tile is on screen.
+ await observer.driver.waitUntil(
+ async () => {
+ try {
+ const displayed = await observer.driver.$(selector).isDisplayed();
+
+ return displayed !== reverse;
+ } catch (e) {
+ // Look the element up again on the next poll.
+ return false;
+ }
+ },
+ {
+ timeout: 3_000,
+ timeoutMsg: `Screensharing tile of ${sharer.name} is ${
+ reverse ? 'still displayed' : 'not displayed'} on ${observer.name}`
+ }
+ );
}
/**