From 28c9eed57abe57a0a0cb0c908356a288dc73440c Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Thu, 2 Jul 2026 15:48:16 +0100 Subject: [PATCH] Document incompatibility between playwright fixtures and MAS (#34101) * Document incompatibility between playwright fixtures and MAS * another comment --- .../playwright-common/src/fixtures/user.ts | 20 ++++++++++++++++++- .../playwright-common/src/utils/context.ts | 2 ++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/playwright-common/src/fixtures/user.ts b/packages/playwright-common/src/fixtures/user.ts index 03a4b55845..a60a28cba9 100644 --- a/packages/playwright-common/src/fixtures/user.ts +++ b/packages/playwright-common/src/fixtures/user.ts @@ -15,7 +15,11 @@ import { sample, uniqueId } from "lodash-es"; import { test as base } from "./panel.js"; import { type Credentials } from "../utils/api.js"; -/** Adds an initScript to the given page which will populate localStorage appropriately so that Element will use the given credentials. */ +/** + * Adds an initScript to the given page which will populate localStorage appropriately so that Element will use the given credentials. + * + * Warning: this is an incomplete implementation, particularly in MAS environments: for example, a logout operation will not work correctly. + */ export async function populateLocalStorageWithCredentials(page: Page, credentials: Credentials) { await page.addInitScript( ({ credentials }) => { @@ -27,6 +31,14 @@ export async function populateLocalStorageWithCredentials(page: Page, credential window.localStorage.setItem("mx_has_pickle_key", "false"); window.localStorage.setItem("mx_has_access_token", "true"); + // XXX: If the homeserver is using MAS, then Element uses additional localstorage settings to store more + // data. The fact that we don't populate them means that, for example, when you hit "Remove this device" in + // the app, it attempts to hit the legacy `/logout` endpoint, which returns a 40x error, which is silently + // ignored. + // + // If you fix this, (1) yay! (2) please remember to update the warning on the doc-comments of this method + // and its callers. + window.localStorage.setItem( "mx_local_settings", JSON.stringify({ @@ -61,6 +73,9 @@ export interface TestFixtures { * but adds an initScript which will populate localStorage with the user's details from * {@link #credentials} and {@link #homeserver}. * + * Warning: this is an incomplete implementation, particularly in MAS environments: for example, a logout operation + * will not work correctly. + * * Similar to {@link #user}, but doesn't load the app. */ pageWithCredentials: Page; @@ -69,6 +84,9 @@ export interface TestFixtures { * A (rather poorly-named) test fixture which registers a user per {@link #credentials}, stores * the credentials into localStorage per {@link #pageWithCredentials}, and then loads the front page of the * app. + * + * Warning: the user credentials are an incomplete implementation, particularly in MAS environments: for example, a logout operation + * will not work correctly. */ user: Credentials; } diff --git a/packages/playwright-common/src/utils/context.ts b/packages/playwright-common/src/utils/context.ts index c11477fe9c..3c8df55459 100644 --- a/packages/playwright-common/src/utils/context.ts +++ b/packages/playwright-common/src/utils/context.ts @@ -14,6 +14,8 @@ import { routeConfigJson } from "./config_json.js"; import { populateLocalStorageWithCredentials } from "../fixtures/user.js"; /** Create a new instance of the application, in a separate browser context, using the given credentials. + * + * Warning: `populateLocalStorageWithCredentials` is an incomplete implementation, particularly in MAS environments: for example, a logout operation will not work correctly. * * @param browser - the browser to use * @param credentials - the credentials to use for the new instance