I'm using the appAPI.message.toBackground() to send a "ready" message from my popup to the background.js which works fine. I am then trying to send a message back to the popup, but I cannot figure out which appAPI.message function to use. my popup has a function registered with appAPI.message.addListener(), but that function is not firing. I've tried using appAPI.message.toAllTabs() and any tabs that are open are receiving that event, but the pop is not.
Any help here would be appreciated
Help get this topic noticed by sharing it on
Twitter,
Facebook, or email.
Twitter,
Facebook, or email.
-
Ok. So the popup appears to run in the background scope. So I have now also tried using appAPI.message.toBackground() but again, the listener i have in my popup code does not get triggered.
-
-
Error between chair and computer!
As it turns out there is an appAPI.message.toPopup() that I missed. -
-
Hello chromecide,
I'm pleased to hear you figured it out :-)
Happy coding! -
-
Hi Chromecide,
I am facing the same problem.
Please can you give me some hints or some sample code.
Thanking you in anticipation.
Thanks -
-
-
-
I am having the same problem as originally described (popup listener doesn't fire) and I am in fact using appAPI.message.toPopup in the background.js file to broadcast the event, so I'm not sure why it's not working for me.
-
-
Hello Lisa,
I understand that you are having an issue with appAPI.message.toPopup. Usually, this works without problems and hence in order to assist further I need to take a closer look.
Therefore, please provide as much of the following information as possible and I will investigate:
- The extension id
- The file/line number where the code snippet can be found
- Which browser and operating system you are testing on, including version numbers
- The exact steps for reproducing the problem
- Any additional useful data, such as URLs, screenshots, videos, ...
-
-
Hello there,
I believe I could be having the same problem as Lisa Lee here, so I will try to refresh the topic if possible.
I am using appAPI.message.listener in both extension.js and my crossriderMain in popup.html as follow :
Extension ID : 54925
Extension.js:27-62
var lid = appAPI.message.addListener(function(msg)
{
switch(msg.action)
{
// Received request to send back page URL
case 'needUrl':
tabURL = window.location.href;
var arr = tabURL.split("/");
tabURL = arr[0] + "//" + arr[2];
console.log("Received needURL, sending to PopUp : " + tabURL);
appAPI.message.toPopup({action: "sendUrl", value : tabURL});
break;
case 'synchronize':
[...] (other stuff, working fine)
break;
// Received message with an unknown action
default:
break;
}
});
Popup.html:8-32
function crossriderMain($)
{
tabURL = "";
// Listener need to be defined first to prevent possible race conditions
appAPI.message.addListener(function(msg)
{
tabURL = msg.value;
console.log("POP : ActiveTab received, TabUrl = [" + tabURL + "]");
refreshEnabled();
});
// Load resource CSS
appAPI.resources.includeCSS('Popup/popup.css');
// Load resource JS
eval(appAPI.resources.get('Popup/popup.js'));
console.log("POP : Sending request to ActiveTab");
appAPI.message.toActiveTab({action: "needUrl"});
// Load resource image
//$('#headerImg').attr('src', appAPI.resources.get('headerImage.jpg'));
}
OS : Windows 8
Chrome version 34.0.1847.131 m
Firefox version 29.0.1
Internet Explorer version 10.0.9200.16897
Exact steps to reproduce the problem :
Quite simple, just installing the extension and opening the popup while checking the browser console.
The problem is that the message is sent from the popup to the ActiveTab without problem, but the response doesn't seem to be catched by the popup listener. I suspected a race condition at first but moving the listeners in front of the rest of the code doesn't seem to help.
Here are two screenshots representing the debug messages concerning the issue :
FireFox (Expected) :
Internet Explorer (Unexpected) :
I don't know if this kind of problem have been solved yet but just in case I'm putting all the information possible, since consulting other posts didn't seem to solve the problem.
Best Regards, -
-
EMPLOYEE
1Hello Devroy,
Thank you for your enquiry. Looking at your extension popup, I can see that you are using a CSS file to add your images to the popup.
This work fine for Chrome and Firefox, but there is a known issue with doing so in Internet Explorer. One of the items affected by the issue is that the messaging API, though you can prove it works if you create a simple extension with popup that uses just the messaging API.
To work around the issue, load popup images by injecting them into your popup using code similar to the following which demonstrates loading images from resources:function crossriderMain($) {
// Resource image
$('<img src="'+appAPI.resources.get('myImage.gif')+'">').prependTo('#myImage');
}
...-
Hey Shlomo - Is this included anywhere in the documentation? If not, could you add it? I spent a day trying to debug why my popup wouldn't function correctly in IE until I found this comment buried in the forums.
-
-
Thanks for your feedback. We have added a note to appAPI.browserAction.setPopup regarding the issue.
-
-
-
-
-
Hello Shlomo,
Thank you for the quick response,
Indeed I didn't expect it was related to CSS (I suppose it's because the extensions behave a lot differently on IE, installed locally and all), and modified my code according to your explanations.
Everything seem fine on the messaging side :)
Thanks again and have a nice day ! -
-
Hello guys,
I am having the same issue as described in above posts and none of the solutions worked for me.
I am trying to send a message from extension code to popup code but function in addListener is not firing at all.
I tried all the workarounds related to this issue but none of them helped.
Here is the info about my extension:
- Extension ID: 72824
- From popup I am sending request to background.js which redirects it to extension code:
case 'start_crawling':
appAPI.tabs.getActive(function(tabInfo) {
var tabId = tabInfo.tabId;
var url = tabInfo.tabUrl;
appAPI.db.async.get('crawling', function(crawling) {
if (crawling.indexOf(tabId) !== -1) {
console.log("Already crawling!");
} else {
...
appAPI.db.async.set('dict_' + tabId, message.dict, appAPI.time.daysFromNow(2), function() {
appAPI.message.toActiveTab({
'action': 'crawl',
'tabInfo': tabInfo
});
});
}
});
});
break; - extension.js where I am sending request back to popup:
case 'crawl':
appAPI.db.async.get('crawling', function(crawling) {
crawling.push(message.tabInfo.tabId);
appAPI.db.async.set('crawling', crawling, appAPI.time.daysFromNow(2), function() {
appAPI.message.toPopup({
'action': 'add_crawl_item',
'tabId': message.tabInfo.tabId,
'tabUrl': message.tabInfo.tabUrl
});
});
});
break; - selection_popup.html:
function crossriderMain($) {
eval(appAPI.resources.get("jquery/select2.min.js"));
appAPI.resources.includeCSS("jquery/select2.min.css");
$('#dicts').select2({
placeholder: "pick dict",
allowClear: false
});
$('#cats').select2({
placeholder: "pick cat",
allowClear: false
});
$('#btn').click(function() {
crawlButtonOnClick($);
});
appAPI.db.async.get('dictionaries', function(dictionaries) {
DICTIONARIES = dictionaries;
dictionariesOnLoad($);
});
appAPI.db.async.get('categories', function(categories) {
CATEGORIES = categories;
categoriesOnLoad($);
});
appAPI.message.addListener(function(msg) {
console.log('here');
switch (msg.action) {
case 'add_crawl_item':
console.log('here 2');
addCrawlItem($, msg.tabId, msg.tabUrl);
break;
}
});
}
messages here and here 2 are never printed to console. - I am using Mozilla Firefox 36.0.4 and Windows 8.1
Please help! :/- view 4 more comments
-
-
-
-
-
Hi, I'm happy to take a look, but before I do so please clarify whether the issue is in Firefox or Chrome. Also, please provide the steps for reproducing the issue.
-
-
I tried the extension both in Firefox 36.0.4 and Chrome 41.0.2272.101 and in none of them the message worked.
Here are the steps reproducing the issue:
-
In my selection_popup.html I have a button, When I click on it, a message with parameters is sent to background.js where I have a handler for that specific message. - It gets to that handler, takes some info about current tab and do some stuff with async database and then it sends a message to extension.js code, where it's caught by another handler.
- In that handler it does some stuff in async database again and then tries to send a message back to popup. Till this step everything works fine. But the message for popup is never caught in popup handler function which is enclosed in crossriderMain() function.
-
-
-
-
-
Hi,
The fact that it's not working in both browsers indicates to me that there is probably an error somewhere in the code.
Hence, I installed the extension on Chrome and can see the message from the popup reaching the background scope. However, in the background scope there is an error in the console as shown. Try fixing the error and see if it resolves the issues and let me know the result.
- view 5 more comments
-
-
-
-
-
-
Now this is an issue I am aware of with appAPI.db.async on FF36 and we are working on a fix which we hope to release in the near future. Do you use the method?
-
-
Another user with the same issue has reported that it's caused by using console.log in the callback. For now, you can workaround the problem by removing console.log methods from the callback.
-
-
-
-
Loading Profile...





