Justson/AgentWeb · error · JsInterfaceObjectException
this object has not offer method javascript to call …
Error message
this object has not offer method javascript to call , please check addJavascriptInterface annotation was be added
What it means
JsInterfaceHolderImpl.addJavaObject performs the same checkObject() validation as the bulk variant: the object must have @JavascriptInterface-annotated methods. If checkSecurity() passes but the object has no annotated methods, JsInterfaceObjectException is thrown. Note that if checkSecurity() fails the method silently returns without adding, so this exception only fires when security checks pass.
Solutions
- Add android.webkit.JavascriptInterface annotations to the public methods you want exposed
- Keep the annotation with ProGuard rules: -keepclassmembers class * { @android.webkit.JavascriptInterface <methods>; } and -keepattributes JavascriptInterface
- Verify at runtime in release builds — annotation stripping differs from debug
- Expose a small dedicated bridge class instead of lambdas/anonymous classes
Example fix
// before
holder.addJavaObject("app", (Runnable) () -> {}); // throws
// after
public class AppBridge {
@android.webkit.JavascriptInterface
public void notifyApp(String msg) { }
}
holder.addJavaObject("app", new AppBridge()); Defensive patterns
Strategy: validation
Validate before calling
if (!isJsBridgeObject(v)) { Log.w(TAG, "skip non-bridge object " + k); return; } Type guard
boolean isJsBridgeObject(Object o) { if (o == null) return false; for (Method m : o.getClass().getMethods()) { if (m.isAnnotationPresent(android.webkit.JavascriptInterface.class)) return true; } return false; } Try / catch
try { holder.addJavaObject(name, obj); } catch (JsInterfaceObjectException e) { Log.e(TAG, "not a JS bridge object", e); } Prevention
- Use explicit bridge classes, not lambdas
- Verify in release builds that annotations survive R8
- Add -keepattributes JavascriptInterface
- Unit-test JS bridge registration in release variant
When it happens
Trigger: Calling holder.addJavaObject(name, obj) with an object whose class lacks public methods annotated with android.webkit.JavascriptInterface, or with a proxy/dynamic class where annotations are not visible.
Common situations: Registering lambdas or anonymous inner classes whose methods are not annotated, wrong annotation import, obfuscation (ProGuard/R8) stripping the @JavascriptInterface annotation at release builds.
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
- This object has not offer method javascript to call ,please…
- activity can not be null .
- ViewGroup is null,Please check your parameters .
- please check webcreator's create method was be called ?
- injected name can not be null
AI-assisted analysis of Justson/AgentWeb@8f7f6adbf0 (2026-09-11).
Data as JSON: /api/errors/c30f88f5a5d6da7b.
Report an issue: GitHub.
Appendix: source
Thrown at agentweb-core/src/main/java/com/just/agentweb/JsInterfaceHolderImpl.java:73
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);
}
return this;
}
private JsInterfaceHolder addJavaObjectDirect(String k, Object v) {
LogUtils.i(TAG, "k:" + k + " v:" + v);
this.mWebView.addJavascriptInterface(v, k);
return this;
}
}
View on GitHub (pinned to 8f7f6adbf0)