Skip to content

Commit f24dcd5

Browse files
authored
Safari: ws cache busting (#27945)
1 parent 1b08a77 commit f24dcd5

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

assets/js/views/App.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,11 @@ export default defineComponent({
172172
return;
173173
}
174174
175-
const loc = window.location;
176-
const protocol = loc.protocol == "https:" ? "wss:" : "ws:";
177-
const uri =
178-
protocol +
179-
"//" +
180-
loc.hostname +
181-
(loc.port ? ":" + loc.port : "") +
182-
loc.pathname +
183-
"ws";
175+
const loc = new URL("ws", window.location.href);
176+
loc.protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
177+
// force Safari to use a fresh connection
178+
loc.searchParams.set("t", String(Date.now()));
179+
const uri = loc.href;
184180
185181
this.ws = new WebSocket(uri);
186182
this.ws.onerror = () => {

tests/ws.spec.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { test, expect } from "@playwright/test";
22
import { start, stop, baseUrl } from "./evcc";
33

4+
const wsPattern = /\/ws\?/;
5+
46
test.use({ baseURL: baseUrl() });
57
test.describe.configure({ mode: "parallel" });
68

@@ -12,7 +14,7 @@ test.afterEach(async () => {
1214
});
1315

1416
test("show loadpoint with connect websocket", async ({ page }) => {
15-
await page.routeWebSocket("/ws", (ws) => {
17+
await page.routeWebSocket(wsPattern, (ws) => {
1618
const server = ws.connectToServer();
1719
ws.onMessage((message) => {
1820
server.send(message);
@@ -28,15 +30,15 @@ test("show loadpoint with connect websocket", async ({ page }) => {
2830
});
2931

3032
test("show no config screen while startup", async ({ page }) => {
31-
await page.routeWebSocket("/ws", () => {
33+
await page.routeWebSocket(wsPattern, () => {
3234
// connect, but don't send any messages
3335
});
3436
await page.goto("/");
3537
await expect(page.getByRole("link", { name: "Let's start configuration" })).toBeHidden();
3638
});
3739

3840
test("show offline when websocket is closed", async ({ page }) => {
39-
await page.routeWebSocket("/ws", (ws) => {
41+
await page.routeWebSocket(wsPattern, (ws) => {
4042
ws.close();
4143
});
4244
await page.goto("/");

0 commit comments

Comments
 (0)