From f24dcd5e117266b09dcb1601426a41d761612924 Mon Sep 17 00:00:00 2001 From: Michael Geers Date: Thu, 5 Mar 2026 14:28:53 +0100 Subject: [PATCH] Safari: ws cache busting (#27945) --- assets/js/views/App.vue | 14 +++++--------- tests/ws.spec.ts | 8 +++++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/assets/js/views/App.vue b/assets/js/views/App.vue index 8ebc5a2b3..f6ec564dc 100644 --- a/assets/js/views/App.vue +++ b/assets/js/views/App.vue @@ -172,15 +172,11 @@ export default defineComponent({ return; } - const loc = window.location; - const protocol = loc.protocol == "https:" ? "wss:" : "ws:"; - const uri = - protocol + - "//" + - loc.hostname + - (loc.port ? ":" + loc.port : "") + - loc.pathname + - "ws"; + const loc = new URL("ws", window.location.href); + loc.protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; + // force Safari to use a fresh connection + loc.searchParams.set("t", String(Date.now())); + const uri = loc.href; this.ws = new WebSocket(uri); this.ws.onerror = () => { diff --git a/tests/ws.spec.ts b/tests/ws.spec.ts index c03ea76a9..0e47c15fc 100644 --- a/tests/ws.spec.ts +++ b/tests/ws.spec.ts @@ -1,6 +1,8 @@ import { test, expect } from "@playwright/test"; import { start, stop, baseUrl } from "./evcc"; +const wsPattern = /\/ws\?/; + test.use({ baseURL: baseUrl() }); test.describe.configure({ mode: "parallel" }); @@ -12,7 +14,7 @@ test.afterEach(async () => { }); test("show loadpoint with connect websocket", async ({ page }) => { - await page.routeWebSocket("/ws", (ws) => { + await page.routeWebSocket(wsPattern, (ws) => { const server = ws.connectToServer(); ws.onMessage((message) => { server.send(message); @@ -28,7 +30,7 @@ test("show loadpoint with connect websocket", async ({ page }) => { }); test("show no config screen while startup", async ({ page }) => { - await page.routeWebSocket("/ws", () => { + await page.routeWebSocket(wsPattern, () => { // connect, but don't send any messages }); await page.goto("/"); @@ -36,7 +38,7 @@ test("show no config screen while startup", async ({ page }) => { }); test("show offline when websocket is closed", async ({ page }) => { - await page.routeWebSocket("/ws", (ws) => { + await page.routeWebSocket(wsPattern, (ws) => { ws.close(); }); await page.goto("/");