You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can use WebView evaluateJavascript on WebViewClient.onPageStarted
Maybe use @JavascriptInterface to get prerequisite preferences from native ¯_(ツ)_/¯
The problem I am having:
Have a server/client application, the bundled is accessed from arbitrary servers that use self signed certs (there is a confirmation step to validate that we are connecting to secure server). We are adding an override to control which self signed certs can be trusted (onReceivedSslError), but since the request is proxied this check is not taken into account in handleProxyRequest and capacitor JS is not injected. (btw this server client interaction happens on local network, thus the need for self signed certs)
Current solution:
@OverridepublicvoidonPageStarted(WebViewwebView,
Stringurl,
Bitmapfavicon) {
// There is no way to get the full list of pluginsList<PluginHandle> pluginList = Arrays.asList(bridge.getPlugin("MyPling"));
try {
// From Bridge.getJSInjector()StringglobalJS = JSExport.getGlobalJS(bridge.getContext(), bridge.getConfig().isLoggingEnabled(), bridge.isDevMode());
StringbridgeJS = JSExport.getBridgeJS(bridge.getContext());
StringpluginJS = JSExport.getPluginJS(pluginList);
StringcordovaJS = JSExport.getCordovaJS(bridge.getContext());
StringcordovaPluginsJS = JSExport.getCordovaPluginJS(bridge.getContext());
StringcordovaPluginsFileJS = JSExport.getCordovaPluginsFileJS(bridge.getContext());
// This would mean getServerUrl wouldn't work correctly (we are not using it)StringlocalUrlJS = "window.WEBVIEW_SERVER_URL = '';";
StringfullScript =
globalJS +
"\n\n" +
localUrlJS +
"\n\n" +
bridgeJS +
"\n\n" +
pluginJS +
"\n\n" +
cordovaJS +
"\n\n" +
cordovaPluginsFileJS +
"\n\n" +
cordovaPluginsJS;
// From JSInjector.getScriptString()webView.post(() -> webView.evaluateJavascript(fullScript, null));
} catch (Exceptionex) {
Logger.error("Unable to export Capacitor JS. App will not function!", ex);
}
Above does work but is hacky, fragile and requires manually adding plugins (since there is no way to access all plugins in bridge afaik).
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, was wondering about the reason to
proxy
request and inject JS vs other methods (that don't involve re-implementing fetch functionality):What happens now:
capacitor/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java
Line 334 in f4e7f19
capacitor/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java
Line 348 in f4e7f19
capacitor/android/capacitor/src/main/java/com/getcapacitor/WebViewLocalServer.java
Lines 371 to 372 in f4e7f19
What could happen:
The problem I am having:
Have a server/client application, the bundled is accessed from arbitrary servers that use self signed certs (there is a confirmation step to validate that we are connecting to secure server). We are adding an override to control which self signed certs can be trusted (onReceivedSslError), but since the request is proxied this check is not taken into account in
handleProxyRequest
and capacitor JS is not injected. (btw this server client interaction happens on local network, thus the need for self signed certs)Current solution:
Above does work but is hacky, fragile and requires manually adding plugins (since there is no way to access all plugins in bridge afaik).
Beta Was this translation helpful? Give feedback.
All reactions