New issue
Advanced search Search tips

Issue 669875 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Dec 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: Bug



Sign in to add a comment

Why? NPMethod called on non-NPObject

Reported by goodmi...@gmail.com, Nov 30 2016

Issue description

THIS TEMPLATE IS FOR FILING BUGS ON THE ANDROID SYSTEM WEBVIEW. GENERAL WEB
BUGS SHOULD BE FILED USING A DIFFERENT TEMPLATE!

Device name: hisilicon 3798mv100
Android version:android 4.4.2
WebView version (from system settings -> Apps -> Android System WebView):
Application:
Application version:

URLs (if applicable):



Steps to reproduce:
(1) please see this java script
==========================
    var g_stb;

    if (typeof(gSTB) == 'undefined'){
        g_stb = {};
    }else{
        g_stb = gSTB;
    }	

    webkit_xpcom.prototype = g_stb;
    common_xpcom.prototype = new webkit_xpcom();

    stb = new common_xpcom();
    stb.InitPlayer();

==========================
(2) I use android webview.
==========================

mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new gSTB(MainActivity.this, mWebView), "gSTB");

public class gSTB {
...
		@JavascriptInterface
		public void InitPlayer() {
			Log.v("gSTB", "InitPlayer");
		}
...
}
==========================
(3) webview load this script.
   when run stb.InitPlayer(), error "NPMethod called on non-NPObject" happen.

Expected result:
   print log

Actual result:


 

Comment 1 by ti...@chromium.org, Dec 16 2016

Cc: torne@chromium.org
Not sure. The following simpler example worked fine for me (Nexus 6P, Android 7.1.2),
WebView 57.0.2952.0 and 54.0.2840.98

Here is the complete code of the test program, the JS variable |myJSInterface| is available immediately and MyJSInterface.init() is called.

Torne, maybe you can shed some light on "NPMethod called on non-NPObject"?

--------------------------------
package test.example.com;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.JavascriptInterface;
import android.webkit.WebView;

public class JSInterfaceTestActivity extends Activity
{
    class MyJSInterface {
        @JavascriptInterface
        public void init() {
            Log.v("JSInterfaceTestActivity", "MyJSInterface.init");
        }
    };

    private MyJSInterface mMyJS = new MyJSInterface();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        WebView webView = new WebView(this);
        setContentView(webView);

        webView.getSettings().setJavaScriptEnabled(true);
        webView.addJavascriptInterface(mMyJS, "myJSInterface");
        String url = "data:text/html," +
                     "<!DOCTYPE html>" +
                     "<html>" +
                     "<head>" +
                     "<script type=\"text/javascript\">" +
                     "myJSInterface.init();" +
                     "</script>" +
                     "</head>" +
                     "</html>";
        webView.loadUrl(url);
    }
}
---------------------------------

Comment 2 by boliu@chromium.org, Dec 21 2016

Labels: Needs-Feedback
Status: WontFix (was: Unconfirmed)
You cannot subclass a js object that's added by addJavascriptInterface. You can only call things on it directly.

Sign in to add a comment