Import base64 utils directly from js-sdk (#12871)

* Import base64 utils directly from js-sdk

See comments in code

* Use the authenticated routes (because the service worker said so)

* Revert "Use the authenticated routes (because the service worker said so)"

This reverts commit 835806d253106b36f337e6387e48d740cc8fb1f2.

* Use the authenticated routes (because the service worker said so)

* Continue fighting Playwright

* Document who is at fault if the import breaks (it's us)

* Update playwright/e2e/timeline/timeline.spec.ts

Co-authored-by: Robin <robin@robin.town>

---------

Co-authored-by: Robin <robin@robin.town>
This commit is contained in:
Travis Ralston 2024-08-06 22:33:13 -06:00 committed by GitHub
parent 8285283cc3
commit 7a4783f907
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View file

@ -720,11 +720,16 @@ test.describe("Timeline", () => {
).toBeVisible(); ).toBeVisible();
}); });
test("should render url previews", async ({ page, app, room, axe, checkA11y }) => { test("should render url previews", async ({ page, app, room, axe, checkA11y, context }) => {
axe.disableRules("color-contrast"); axe.disableRules("color-contrast");
await page.route( // Element Web uses a Service Worker to rewrite unauthenticated media requests to authenticated ones, but
"**/_matrix/media/v3/thumbnail/matrix.org/2022-08-16_yaiSVSRIsNFfxDnV?*", // the page can't see this happening. We intercept the route at the BrowserContext to ensure we get it
// post-worker, but we can't waitForResponse on that, so the page context is still used there. Because
// the page doesn't see the rewrite, it waits for the unauthenticated route. This is only confusing until
// the js-sdk (and thus the app as a whole) switches to using authenticated endpoints by default, hopefully.
await context.route(
"**/_matrix/client/v1/media/thumbnail/matrix.org/2022-08-16_yaiSVSRIsNFfxDnV?*",
async (route) => { async (route) => {
await route.fulfill({ await route.fulfill({
path: "playwright/sample-files/riot.png", path: "playwright/sample-files/riot.png",
@ -750,6 +755,7 @@ test.describe("Timeline", () => {
const requestPromises: Promise<any>[] = [ const requestPromises: Promise<any>[] = [
page.waitForResponse("**/_matrix/media/v3/preview_url?url=https%3A%2F%2Fcall.element.io%2F&ts=*"), page.waitForResponse("**/_matrix/media/v3/preview_url?url=https%3A%2F%2Fcall.element.io%2F&ts=*"),
// see context.route above for why we listen for the unauthenticated endpoint
page.waitForResponse("**/_matrix/media/v3/thumbnail/matrix.org/2022-08-16_yaiSVSRIsNFfxDnV?*"), page.waitForResponse("**/_matrix/media/v3/thumbnail/matrix.org/2022-08-16_yaiSVSRIsNFfxDnV?*"),
]; ];

View file

@ -17,7 +17,15 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
import { encodeUnpaddedBase64 } from "matrix-js-sdk/src/matrix"; // Note: we don't import the base64 utils from `matrix-js-sdk/src/matrix` because this file
// is used by Element Web's service worker, and importing `matrix` brings in ~1mb of stuff
// we don't need. Instead, we ignore the import restriction and only bring in what we actually
// need.
// Note: `base64` is not public in the js-sdk, so if it changes/breaks, that's on us. We should
// be okay with our frequent tests, locked versioning, etc though. We'll pick up problems well
// before release.
// eslint-disable-next-line no-restricted-imports
import { encodeUnpaddedBase64 } from "matrix-js-sdk/src/base64";
import { logger } from "matrix-js-sdk/src/logger"; import { logger } from "matrix-js-sdk/src/logger";
/** /**