Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4584424
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:21:11+00:00 2026-05-21T21:21:11+00:00

I am writing a chrome plugin in which I want to register click event,

  • 0

I am writing a chrome plugin in which I want to register click event, means whenever we click on DOM window, the handler inside plugin will be called. For that I am using CPlugin class. The constructor is called from NPP_New(/argument/).

When I run the browser and click anywhere, I noticed that ScriptablePluginObject’s HasProperty and GetProperty function called with identifier name “handleEvent”.
I don’t understand how to handle the event.

Can anyone guide me please?

/////////////CODE///////////////////

static NPIdentifier sFunction_id;

// Called from NPP_New()
CPlugin::CPlugin(NPP pNPInstance) :
    m_pNPInstance(pNPInstance),
    m_pNPStream(NULL),
    m_bInitialized(FALSE),
    m_pScriptableObject(NULL)
{
    bool boRet;
    NPError rv;
    char szText[300];

    LogMessage("CPlugin::CPlugin::Enter");

    sFunction_id = NPN_GetStringIdentifier("handleEvent");

    rv = NPN_GetValue(m_pNPInstance, NPNVWindowNPObject, &sWindowObj);
    if (NPERR_NO_ERROR != rv)
    {
        LogMessage("CPlugin::CPlugin::NPN_GetValue() failed.");
    }

    NPObject *scriptObj = NPN_CreateObject(m_pNPInstance, GET_NPOBJECT_CLASS(ScriptablePluginObject));
    if (!scriptObj)
    {
        LogMessage("CPlugin::CPlugin::NPN_CreateObject failed");
    }

    NPVariant params[3]; 
    // arg0: event type 
    STRINGZ_TO_NPVARIANT("click", params[0]);
    // arg1: listener 
    params[1].type = NPVariantType_Object; 
    params[1].value.objectValue = scriptObj;
    // arg2: useCapture 
    params[2].type = NPVariantType_Bool; 
    params[2].value.boolValue = true;

    NPIdentifier addEventListener_id =  NPN_GetStringIdentifier("addEventListener"); 

    NPVariant result_add; 
    // windowObject.addEventListener("click", listener, false); 
    if (!NPN_Invoke(m_pNPInstance, sWindowObj, addEventListener_id, &params[0], 3, &result_add))
    {
        LogMessage("CPlugin::CPlugin::NPN_Invoke for addEventListener failed");
    }

    NPIdentifier removeEventListener_id = NPN_GetStringIdentifier("removeEventListener");
    NPVariant result_remove;
    // windowObject.removeEventListener("click", listener, false); 
    if (!NPN_Invoke(m_pNPInstance, sWindowObj, removeEventListener_id, &params[0], 3, &result_remove))
    {
        LogMessage("CPlugin::CPlugin::NPN_Invoke for removeEventListener failed");
    }

    NPN_ReleaseVariantValue(&result_add);
    NPN_ReleaseVariantValue(&result_remove);
    NPN_ReleaseObject(scriptObj);

    const char *ua = "This is test plugin";//NPN_UserAgent(m_pNPInstance);
    strcpy(m_String, ua);
    LogMessage("CPlugin::CPlugin::Exit");
}

// In HasProperty and GetProperty, nothing has been done.

bool
ScriptablePluginObject::HasProperty(NPIdentifier name)
{
    LogMessage("ScriptablePluginObject::HasProperty");
    char *nam = NPN_UTF8FromIdentifier(name);
    LogMessage(nam);
    NPN_MemFree(nam);

    return true;
}

bool
ScriptablePluginObject::GetProperty(NPIdentifier name, NPVariant *result)
{
    LogMessage("ScriptablePluginObject::GetProperty");
    char *nam = NPN_UTF8FromIdentifier(name);
    LogMessage(nam);
    NPN_MemFree(nam);

    return true;
}

///////////CODE///////////

Both of the above classes are taken from google code. I am only adding event listener on NPObject.
What is wrong with it? Any idea?

-Abhay

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:21:12+00:00Added an answer on May 21, 2026 at 9:21 pm

    Your on the track, but you require some more changes:

    1. Create a brand new NPClass, you can name this MouseClickEvent or some sort.
    2. Implement your mouse event listener functionality in the InvokeDefault of the MouseClickEvent class.
    3. Now with NPN_CreateObject create your NPObject from the instance of MouseClickEvent
    4. You pass that NPObject as a second parameter to the addEventListener you mentioned above.

    Hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a Chrome extension which dynamically changes the content of the popup window
I am writing a chrome plugin in which I would like to receive events
I am writing a Chrome extension, and I want a login window to be
I'm writing into a session cookie from my plugin in chrome. The browser seems
I am writing a chrome extension that is a 'content script' I want to
I am writing a Chrome extension which needs to access minus.com by OAuth 2.0.
This is my first hack at writing a Chrome extension. I want it to
I am writing codes for a Chrome extension that needs to access minus.com, which
I am writing a chrome extension where I want to fetch all the images
I'm writing a Chrome extension, and want to write one JS file, that provides

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.