Justson/AgentWeb · error · JsInterfaceObjectException

This object has not offer method javascript to call ,please…

Error message

This object has not offer method javascript to call ,please check addJavascriptInterface annotation was be added

What it means

JsInterfaceHolderImpl.addJavaObjects validates each object with checkObject(), which requires the class to expose methods annotated with @JavascriptInterface. An object with no such annotated methods is rejected with JsInterfaceObjectException because JavaScript would have nothing callable, a security/compatibility guard (especially needed on API 17+).

Solutions

  1. Annotate the public methods to expose with android.webkit.JavascriptInterface
  2. Ensure the class passed actually declares annotated methods itself (not only inherited/proxied ones)
  3. Check the import — it must be android.webkit.JavascriptInterface, not another annotation
  4. Only register objects intended as JS bridges; remove unrelated objects from the map

Example fix

// before
class Bridge { public void go(){} } // no annotation -> throws
// after
class Bridge {
    @android.webkit.JavascriptInterface
    public void go(){}
}
Defensive patterns

Strategy: validation

Validate before calling

boolean ok = false; for (Method m : obj.getClass().getMethods()) { if (m.isAnnotationPresent(JavascriptInterface.class)) { ok = true; break; } } if (!ok) return;

Type guard

boolean isJsBridge(Object o) { for (Method m : o.getClass().getMethods()) { if (m.isAnnotationPresent(android.webkit.JavascriptInterface.class)) return true; } return false; }

Try / catch

try { holder.addJavaObjects(map); } catch (JsInterfaceObjectException e) { Log.e(TAG, "object lacks @JavascriptInterface methods", e); }

Prevention

When it happens

Trigger: Adding a plain POJO without any @JavascriptInterface-annotated public methods via addJavaObjects(map), or using methods with the old pre-17 @JavascriptInterface semantics/imports (wrong annotation package).

Common situations: Importing com.sun.javascript or a custom @JavascriptInterface instead of android.webkit.JavascriptInterface, annotating methods on a superclass but building against a SDK that strips annotations, or adding DTO/config objects by mistake.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Justson/AgentWeb@8f7f6adbf0 (2026-09-11). Data as JSON: /api/errors/fd1f251211531840. Report an issue: GitHub.

Appendix: source

Thrown at agentweb-core/src/main/java/com/just/agentweb/JsInterfaceHolderImpl.java:58

    JsInterfaceHolderImpl(WebCreator webCreator, AgentWeb.SecurityType securityType) {
        super(webCreator, securityType);
        this.mWebCreator = webCreator;
        this.mWebView = mWebCreator.getWebView();
        this.mSecurityType = securityType;
    }

    @Override
    public JsInterfaceHolder addJavaObjects(Map<String, Object> maps) {
        if (!checkSecurity()) {
            LogUtils.e(TAG, "The injected object is not safe, give up injection");
            return this;
        }
        Set<Map.Entry<String, Object>> sets = maps.entrySet();
        for (Map.Entry<String, Object> mEntry : sets) {
            Object v = mEntry.getValue();
            boolean t = checkObject(v);
            if (!t) {
                throw new JsInterfaceObjectException("This object has not offer method javascript to call ,please check addJavascriptInterface annotation was be added");
            } else {
                addJavaObjectDirect(mEntry.getKey(), v);
            }
        }
        return this;
    }

    @Override
    public JsInterfaceHolder addJavaObject(String k, Object v) {
        if (!checkSecurity()) {
            return this;
        }
        boolean t = checkObject(v);
        if (!t) {
            throw new JsInterfaceObjectException("this object has not offer method javascript to call , please check addJavascriptInterface annotation was be added");
        } else {
            addJavaObjectDirect(k, v);
        }

View on GitHub (pinned to 8f7f6adbf0)