From 9eb565cddd30888125d1503d1c0a5aa5aa5e48cb Mon Sep 17 00:00:00 2001 From: jcesarmobile Date: Wed, 13 Mar 2024 16:16:06 +0100 Subject: [PATCH] fix(android): Remove path from allowedOriginRules (#7293) --- .../capacitor/src/main/java/com/getcapacitor/Bridge.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java index b5bc69eab..506477b53 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/Bridge.java +++ b/android/capacitor/src/main/java/com/getcapacitor/Bridge.java @@ -254,7 +254,12 @@ private void loadWebView() { // Start the local web server JSInjector injector = getJSInjector(); if (WebViewFeature.isFeatureSupported(WebViewFeature.DOCUMENT_START_SCRIPT)) { - WebViewCompat.addDocumentStartJavaScript(webView, injector.getScriptString(), Collections.singleton(appUrl)); + String allowedOrigin = appUrl; + Uri appUri = Uri.parse(appUrl); + if (appUri.getPath() != null) { + allowedOrigin = appUri.toString().replace(appUri.getPath(), ""); + } + WebViewCompat.addDocumentStartJavaScript(webView, injector.getScriptString(), Collections.singleton(allowedOrigin)); injector = null; } localServer = new WebViewLocalServer(context, this, injector, authorities, html5mode);