From 0bbe43b5bef581ab89cbe1908c0857c744449a42 Mon Sep 17 00:00:00 2001 From: Manuel Beck Date: Fri, 13 Mar 2026 17:24:25 +0100 Subject: [PATCH] fix: log missing optional assets not as exception - When no plugins are added, `cordova_plugins.js` is not present and will give an error in console: `java.io.FileNotFoundException: www/cordova_plugins.js`` - Chromium tries to load `favicon.ico` which is not present: `java.io.FileNotFoundException: www/favicon.ico` - Generated-By: GPT-5.3-Codex, GitHub Copilot Chat --- .../cordova/engine/SystemWebViewClient.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java index 47da339e..52e46daa 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewClient.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewClient.java @@ -111,6 +111,13 @@ public class SystemWebViewClient extends WebViewClient { return new WebResourceResponse(mimeType, null, is); } catch (Exception e) { + // Some files are requested by default but might not exist in a valid project setup. + // When these files are missing, the request should quietly fall through instead of + // being logged as an application error. + if (isOptionalMissingAsset(path, e)) { + LOG.d(TAG, "Optional Web resource not found at \"" + path + "\""); + return null; + } e.printStackTrace(); LOG.e(TAG, "Exception handling Web resource at \"" + path + "\"", e); } @@ -132,6 +139,24 @@ public class SystemWebViewClient extends WebViewClient { } } + /** + * Returns `true` when the request failure is expected and non-fatal. + * + * Some web resources are requested by default but might not exist in a valid project setup: + * - {@code cordova_plugins.js} can be absent when no plugins are installed. + * - {@code favicon.ico} is often requested by the WebView/Chromium engine automatically. + * + * When these files are missing, the request should quietly fall through instead of being logged + * as an application error. + */ + private static boolean isOptionalMissingAsset(String path, Exception exception) { + if (!(exception instanceof FileNotFoundException)) { + return false; + } + + return "cordova_plugins.js".equals(path) || "favicon.ico".equals(path); + } + /** * Give the host application a chance to take over the control when a new url * is about to be loaded in the current WebView.