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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:13:23+00:00 2026-06-03T03:13:23+00:00

I’m using a context-menu item click to show a dialog (using JQuery/Bootstrap) that lets

  • 0

I’m using a context-menu item click to show a dialog (using JQuery/Bootstrap) that lets users submit the text they selected to a web service via AJAX (this all works perfectly). Once submitted, I intend to display an Add-on SDK notification to say ‘Thanks for your submission’.

Now, I know I need to send a message from the content script to the Add-on script to show the notification, but my message doesn’t arrive when sent from a callback function.

My add-on code (extract):

var pageMod = require("page-mod");
pageMod.PageMod({
  include: ['*'],
  contentScriptWhen: "end",
  contentScriptFile: [ data.url("js/content.js") ],

  onAttach: function onAttach( worker, mod) {
    worker.port.on("submittedNotif", function(msg) {
        console.log('Hello');
        notifications.notify({ ... });
    })
  }
});

Content-script follows. I’ve indicated the situations where the message arrived, and where it doesn’t.

// Handle the context-menu Item's click and show the dialog

self.on("click", function(node,data) {
    self.port.emit("submittedNotif", '*** DOES NOT ARRIVE ***');
    showDialog( 'DialogName', function (response) { /* Do stuff */ });
})

self.port.emit("submittedNotif", '*** Arrives OK ***');

function showDialog( str, response) {
    // Dialog stuff
    self.port.emit("submittedNotif", '*** DOES NOT ARRIVE ***');
}

I’m told self is a global object, so I shouldn’t have to pass it as a parameter, surely. It’s just not clear to me how trying to send via self.port.emit should work differently depending on where it’s used within the content script. I’m not aware of any threading issue, for example. Perhaps this is a gap in my JavaScript knowledge, but can anyone tell me what I’m doing wrong?

  • 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-03T03:13:24+00:00Added an answer on June 3, 2026 at 3:13 am

    I solved my own problem. Here’s how, and what I learned.

    Firstly, the content-script, and the context-menu Item’s click handler:

    self.on("click", function(node,data) {
        self.postMessage({ kind:'submittedNotif', msg: 'Just clicked'})
        showDialog( self, 'DialogName', function (response) { /* Do stuff */ });
    })
    

    Now, the old self.port.emit got me nowhere, but switching to self.postMessage and adding an onMessage() to the context-menu Item finally gives me the event I want.

    I now also pass self to the showDialog() method [which goes against what I was told about self being global…?!], as the parameter ‘eventHandler’:

    function showDialog( eventHandler, str, response) {
        // Dialog stuff
        eventHandler.postMessage({ kind:'submittedNotif', msg: 'Thank you for your submission'});
    }
    

    Again, I drop the self.port.emit, switching to self.postMessage, and calling that on the handler that was passed-in.

    And finally, the notifications.notify({ ... }); call gets moved from the PageMod‘s onAttach() to the menu Item’s onMessage(). In short, everything that happens in response to that click now happens within the scope of the menu item.

    All works now. Perhaps this all seems obvious in retrospect – but the documentation definitely confused rather than clarified, especially the difference between port and postMessage()

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

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.