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

  • Home
  • SEARCH
  • 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 7893687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:11:47+00:00 2026-06-03T07:11:47+00:00

I am currently building a browser extension that injects javascript/jquery into certain pages, and

  • 0

I am currently building a browser extension that injects javascript/jquery into certain pages, and i am having a weird issue, where forcing .click() events are not working from my injected code. The strange bit is that it works completely fine if i make the call from my console js console.

I dont really understand what the problem is. It seems that all of my other calls are working fine. I can bind to click events using .click(function(){...}) (so clearly my jquery has been loaded properly), and call methods when things are clicked (so clearly my jquery has been loaded properly), but the second that i try to force a click, the call just does not go through.

Can anybody explain what is happening, or a way that i can get around it?

(i can not recreate this issue, because the problem clearly has to do with injecting the js in an extension)

this is the best i can do for recreation:

//I have tried all of these separately 
console.log($("#this_is_an_id"))  //This returns the correct element

$("#this_is_an_id").click()       //This does not work at all

$("#this_is_an_id").trigger("click") //I have also tried this without success

$("#this_is_an_id").click(function(){ console.log("stuff") }) //This works fine.

Really, at this point, i am assuming it is not my fault, but something that is wrong with the browser’s method of injecting script. I am sorta looking for really hackey ways to fix this, i also tried eval('$("#this_is_an_id").trigger("click")'). Does anybody have any other suggestions?

  • 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-06-03T07:11:49+00:00Added an answer on June 3, 2026 at 7:11 am

    I finally found a very excellent answer/work around to this issue here:
    Trigger events from Firefox browser extension?

    From user cms:

    First of all, for click events, you need to create an event object with type MouseEvents, not HTMLEvents, and use event.initMouseEvent instead of event.initEvent.

    To access the document of the current tab of Firefox from a XUL overlay, you can use the content.document property, but since you already have access to the DOM element you want to click, you can use the Node.ownerDocument property, which will refer to the top-level document object for this node.

    I have made a simple function to simulate MouseEvents:

    function triggerMouseEvent(element, eventName, userOptions) {
      var options = { // defaults
        clientX: 0, clientY: 0, button: 0,
        ctrlKey: false, altKey: false, shiftKey: false,
        metaKey: false, bubbles: true, cancelable: true
         // create event object:
      }, event = element.ownerDocument.createEvent("MouseEvents");
    
      if (!/^(?:click|mouse(?:down|up|over|move|out))$/.test(eventName)) {
        throw new Error("Only MouseEvents supported");
      }
    
      if (typeof userOptions != 'undefined'){ // set the userOptions
        for (var prop in userOptions) {
          if (userOptions.hasOwnProperty(prop))
            options[prop] = userOptions[prop];
        }
      }
      // initialize the event object
      event.initMouseEvent(eventName, options.bubbles, options.cancelable,
                           element.ownerDocument.defaultView,  options.button,
                           options.clientX, options.clientY, options.clientX,
                           options.clientY, options.ctrlKey, options.altKey,
                           options.shiftKey, options.metaKey, options.button,
                           element);
      // dispatch!
      element.dispatchEvent(event);
    }
    

    Usage:
    triggerMouseEvent(element, ‘click’);

    Check a test usage here.

    You can pass also an object as the third argument, if you want to change the values of the event object properties.

    Thank you so much for this answer. O_O

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

Sidebar

Related Questions

I'm currently building an JavaScript project that uses NodeJS and some objects are shared
I'm currently building a user control that displays a message when a Repeater is
I'm currently building a web form using APEX that is losely modelled after a
I am building an extension for Chrome browser. I wish to be able to
i am currently building one of my newest websites which is a browser based
I'm building a Rails application that deals with file uploads through CarrierWave. Currently, larger
Here's a snippet of a web server that I am currently building... // ...
I'm currently PHP building a script that has to update statistics when it finishes
I'm currently building a WordPress theme that I would like to have a header
I'm currently building up a PHP script that will answer HTTP 304 Not Modified

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.