From 0de2fd942f62460e016d464529478645ab7766ff Mon Sep 17 00:00:00 2001 From: litruv Date: Tue, 28 Jul 2026 00:18:28 +1000 Subject: [PATCH] Prefer native UnifiedPush gateway discovery to avoid WebView CORS failures. --- src/app/utils/backgroundSync.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/app/utils/backgroundSync.ts b/src/app/utils/backgroundSync.ts index dbe334c..b2f9cba 100644 --- a/src/app/utils/backgroundSync.ts +++ b/src/app/utils/backgroundSync.ts @@ -55,6 +55,8 @@ interface MatrixBackgroundSyncPlugin { setAppForeground(options: { foreground: boolean }): Promise; /** Returns fetch state and current UnifiedPush registration details. */ getStatus(): Promise; + /** Native Matrix gateway discovery for a UnifiedPush endpoint (avoids WebView CORS). */ + resolveUnifiedPushGateway(options: { endpoint: string }): Promise<{ gatewayUrl: string }>; addListener( eventName: 'unifiedPushNewEndpoint', listenerFunc: (event: UnifiedPushEndpointEvent) => void @@ -141,6 +143,17 @@ const normalizeDistributors = (raw: UnifiedPushStatus['distributors']): string[] }; const resolveUnifiedPushGateway = async (endpoint: string): Promise => { + // Prefer native HTTP — ntfy/Matrix gateway responses omit CORS headers, so + // WebView fetch fails with TypeError: Failed to fetch and wrongly falls back. + try { + const { registerPlugin } = await loadCapacitorCore(); + const MatrixBackgroundSync = registerPlugin('MatrixBackgroundSync'); + const result = await MatrixBackgroundSync.resolveUnifiedPushGateway({ endpoint }); + if (result?.gatewayUrl) return result.gatewayUrl; + } catch (err) { + console.warn('[BackgroundSync] Native UnifiedPush gateway discovery failed:', err); + } + try { const discoveryUrl = new URL(endpoint); discoveryUrl.pathname = '/_matrix/push/v1/notify';