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 7458253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:25:26+00:00 2026-05-29T13:25:26+00:00

Scenario I’m writing a Chrome extension / userscript to add a little usability to

  • 0

Scenario

I’m writing a Chrome extension / userscript to add a little usability to a third-party site. The page that the extension is made for has a few elements that have `click` event listeners attached (per-element, no bubbling) via `addEventListener` (the `onclick` and other properties are empty). My extension clones (`cloneNode`) one of the elements and appends it to the list.

For example with this,

<div id="list">
  <div id="d1">A</div>
  <div id="d2">B</div>
  <div id="d3">C</div>
</div>

my extension would add a D element.


Problem

Extending the list works fine, but when the original nodes are clicked, they perform the expected action, while clicking the new one does nothing.


Tests

Test 1

I examined the event listeners of the elements in Chrome’s Developer Tools and tried copying the anonymous function to my new elements with `addEventListener` (making sure to duplicate the parameters), but that did not work. It did perform some of the expected actions, but not all of them.

Test 2

I tried anfilat’s suggestion of using the trick from [this question][1]. I inserted a `script` block that then called `addEventHanlder` for the new node, and it did indeed have the new handler (with a `sourceName` referring to the site—the page, not the `.JS` file—instead of the extension), however it still threw a variable not found error.


Hypothesis

I suspect that it is a domain issue because the click-handler calls a function in an external `.JS` as referenced in the `sourceName` and `lineNumber` of the event listener as seen below. Note that the `listenerBody` is identical, but the sources differ.


Question

Is there a way to access, copy, or clone the handlers of an element and/or edit the `lineNumber` and `sourceName`?


Appendix A: Diagrams

Figure 1: Handlers of original elements referring to a .JS on the site (with slight filename edits):

Site

Figure 2: Handlers of new elements referring to the extension:

Extension

  • 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-29T13:25:26+00:00Added an answer on May 29, 2026 at 1:25 pm

    I wrote the small working test.

    Crome extension inject script:

    var myScriptElement = document.createElement('script'); 
    myScriptElement.innerHTML =
      'b=document.getElementById("button");' +
      'c=b.cloneNode(true);' +
      'b.parentElement.appendChild(c);' +
      'c.addEventListener("click", function(e){foo("from new button")}, false);';
    document.querySelector('head').appendChild(myScriptElement);
    

    test html:

    <html>
    <script type='text/javascript' src='test.js'></script>
    <body>
    <button id='button'>test</button>
    <script>
    document.getElementById('button').addEventListener('click', function (event) {
      foo('from page');
    }, false);
    </script>
    </body>
    </html>
    

    and test.js:

    function foo(text) {
      console.log(text);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is the scenario: I'm writing an app that will watch for any changes
The scenario is that we are writing an application to let people to fill
I'm writing a VS extension that needs to know the full path of the
Currently I am writing Perl script that creates LoadRunner scenario, execute the test, collect
Scenario: I'm currently writing a layer to abstract 3 similar webservices into one useable
I was writing some ASP.NET control when I came to the scenario where I
Scenario: You have an ASP.Net webpage that should display the next image in a
Scenario is that we send out thousands of emails through SMTP server. Content is
Scenario: An event is raised in class A that needs to be handled by
I got the following scenario: I am writing an app, which acts like a

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.