Skip to content

Webinfc bridge classes push JS via legacy loadUrl("javascript:...") instead of evaluateJavascript #531

Description

@jim-daf

Where

app/src/main/java/com/ds/avare/webinfc/, in the three WebApp*Interface classes that push state into the embedded WebViews:

  • WebAppAircraftInterface.java
  • WebAppMapInterface.java
  • WebAppPlanInterface.java

Each one builds a small JS snippet and ships it via mWebView.loadUrl("javascript:..."+...). Examples:

mWebView.loadUrl("javascript:list_clear()");
String func = "javascript:plan_add(" + (String)msg.obj + ")";
mWebView.loadUrl(func);
mWebView.loadUrl("javascript:wnb_set('" + data + "')");

There are 26 such calls in total across the three files.

Why this matters

loadUrl("javascript:...") is the legacy way of running JS in a WebView and it counts as a navigation. Each call pushes an entry into the WebView back/forward list, can fire onPageStarted / onPageFinished, and races with whatever the page is doing at the time. In Avare this fires constantly while the user is on the map, the plan, the W&B, the aircraft, etc. windows, because state changes (weather, plan add, list update, etc.) come in as Message posts on mHandler.

WebView.evaluateJavascript(script, callback) is the recommended replacement. It runs the script without touching navigation and is available on every API level Avare currently targets.

Suggested fix

Strip the "javascript:" prefix from each JS snippet and switch the call site to mWebView.evaluateJavascript(script, null). No other behaviour changes.

I have a small PR ready that does exactly that across the three files.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions