From 1b61caa879d1fc005b58a2ddc9f586755a60782b Mon Sep 17 00:00:00 2001 From: Erwan Leboucher Date: Thu, 23 Jul 2026 23:22:04 +0200 Subject: [PATCH] fix: use window origin for call widget parentUrl on Tauri --- src/app/plugins/call/CallEmbed.intent.test.ts | 16 +++++++++++ src/app/plugins/call/CallEmbed.ts | 4 +-- src/app/utils/platform.test.ts | 28 ++++++++++++++++++- src/app/utils/platform.ts | 9 ++++++ 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/app/plugins/call/CallEmbed.intent.test.ts b/src/app/plugins/call/CallEmbed.intent.test.ts index 637760942..815505eeb 100644 --- a/src/app/plugins/call/CallEmbed.intent.test.ts +++ b/src/app/plugins/call/CallEmbed.intent.test.ts @@ -157,4 +157,20 @@ describe('CallEmbed.getWidget', () => { expect(url.pathname).toContain('/public/element-call/index.html'); }); + + it('uses the actual window origin as parentUrl on Tauri, not the canonical app URL', () => { + vi.stubGlobal('window', { + location: { + origin: 'https://tauri.localhost', + protocol: 'https:', + host: 'tauri.localhost', + hostname: 'tauri.localhost', + }, + }); + const room = createRoom(false); + const widget = CallEmbed.getWidget(mx, room, ElementCallIntent.StartCallVoice, 'dark'); + const url = new URL(widget.getCompleteUrl({ currentUserId: '@alice:example.com' })); + + expect(url.searchParams.get('parentUrl')).toBe('https://tauri.localhost'); + }); }); diff --git a/src/app/plugins/call/CallEmbed.ts b/src/app/plugins/call/CallEmbed.ts index 4f6091ec3..0e99c08f2 100644 --- a/src/app/plugins/call/CallEmbed.ts +++ b/src/app/plugins/call/CallEmbed.ts @@ -10,7 +10,7 @@ import { } from 'matrix-widget-api'; import { CallWidgetDriver } from './CallWidgetDriver'; import { trimTrailingSlash } from '../../utils/common'; -import { getAppOrigin } from '../../utils/platform'; +import { getWindowOrigin } from '../../utils/platform'; import type { ElementCallThemeKind, ElementMediaStateDetail } from './types'; import { color, config } from 'folds'; import { ElementCallIntent, ElementWidgetActions } from './types'; @@ -97,7 +97,7 @@ export class CallEmbed { ): Widget { const userId = mx.getSafeUserId(); const deviceId = mx.getDeviceId() ?? ''; - const clientOrigin = getAppOrigin(); + const clientOrigin = getWindowOrigin(); const widgetId = 'call-embed'; const params = new URLSearchParams({ diff --git a/src/app/utils/platform.test.ts b/src/app/utils/platform.test.ts index 6a322b9bd..263793cee 100644 --- a/src/app/utils/platform.test.ts +++ b/src/app/utils/platform.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'; -import { getAppOrigin } from './platform'; +import { getAppOrigin, getWindowOrigin } from './platform'; import { isTauri } from '@tauri-apps/api/core'; vi.mock('@tauri-apps/api/core', () => ({ @@ -44,3 +44,29 @@ describe('getAppOrigin', () => { expect(getAppOrigin()).toBe('https://app.sable.moe'); }); }); + +describe('getWindowOrigin', () => { + afterEach(() => { + vi.unstubAllGlobals(); + }); + + it('returns the real tauri:// origin when window.location.origin is the opaque "null"', () => { + vi.stubGlobal('location', { + origin: 'null', + hostname: 'localhost', + protocol: 'tauri:', + host: 'localhost', + }); + expect(getWindowOrigin()).toBe('tauri://localhost'); + }); + + it('returns window.location.origin in a normal web environment', () => { + vi.stubGlobal('location', { + origin: 'https://app.example.com', + hostname: 'app.example.com', + protocol: 'https:', + host: 'app.example.com', + }); + expect(getWindowOrigin()).toBe('https://app.example.com'); + }); +}); diff --git a/src/app/utils/platform.ts b/src/app/utils/platform.ts index c9d3b2bc3..885288dd0 100644 --- a/src/app/utils/platform.ts +++ b/src/app/utils/platform.ts @@ -38,3 +38,12 @@ export function getAppOrigin(): string { ? `${window.location.protocol}//${window.location.host}` : window.location.origin; } + +// Runtime origin of the current window. getAppOrigin() returns the canonical +// app URL on Tauri, which does not match the parent frame — use this for +// widget parentUrl / postMessage targetOrigin. +export function getWindowOrigin(): string { + return window.location.origin === 'null' + ? `${window.location.protocol}//${window.location.host}` + : window.location.origin; +}