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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T00:05:18+00:00 2026-06-11T00:05:18+00:00

I use the Mozilla’s Add-on Builder. I am looking for a way to remove

  • 0

I use the Mozilla’s Add-on Builder. I am looking for a way to remove an event listener in a contentScript. I use the port way to communicate between add-on script code and the content script code.

The problem is the callback on event “response” is called more than once. I want it to be called once and declared in the callback of the event show.

Can someone help me with that?

main.js code:

var Panel = require("panel").Panel;
var popup_panel = Panel({
    width: 286,
    height: 340,
    contentURL: require("self").data.url("popup.html"),
    allow: { script: true },
    contentScriptWhen: "end",
    contentScriptFile : [
        require("self").data.url("test.js")
    ],
    onShow: function(){
        this.port.emit("show");
        var pan = this;
        this.port.on("hide", function(){pan.hide();});
    }
});

var Widget = require("widget").Widget;
var widget = Widget({
    id: "mozilla-icon",
    label: "My Mozilla Widget",
    contentURL: "http://www.mozilla.org/favicon.ico",
    panel: popup_panel
});

popup_panel.port.on("get", function(){
    popup_panel.port.emit("response");
});

Content script (test.js):

self.port.on("show", function(){
    console.log("show");
    function response(){
        console.log("reponse called");
    }

    self.port.emit("get");
    self.port.once("response", response);
    self.port.removeListener("response", response);
});

full source code

  • 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-11T00:05:19+00:00Added an answer on June 11, 2026 at 12:05 am

    Finally I found the problem. It is a bug in the add-on kit. In the file api-utils/lib/content/content-worker.js in the function removeListener the index is always -1.

    The parameter given in the indexOf is the name of the event and it search a function. It is incorrect.

    So to solve the problem I replace the line let index = listeners[name].indexOf(name); by let index = listeners[name].indexOf(callback);.

    EDIT

    The bug has been fixed. It will publish in the version 1.10 see here

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

Sidebar

Related Questions

I'm trying to use Storage mechanism in Mozilla platform (in thundebird 3.0). The following
There are some events that I can use for handling drag & drop: https://developer.mozilla.org/en/DragDrop/Drag_and_Drop
What web browsers use the __proto__ ? Mozilla states that: Note that __proto__ may
I use the webkit/mozilla border radius and box shadow CSS properties, but I want
Looking through the Mozilla JavaScript site, I see that JavaScript 1.8 has a lot
I have an application that use mozilla browser for samsung galaxy tab 7 (android
In the lab I work in, we use Mozilla 1.7 for Sun Java™ Desktop
I have an application that makes use of the Mozilla LDAP library. We're diagnosing
I would like to use SpiderMonkey ( the javascript engine from Mozilla ) in
I'm embedding Mozilla's SpiderMonkey in my application and would like to use its new

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.