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);