0

Im trying to display a list of all installed extensions in my popup.html. When the browser action is clicked, i send a request from popup.js to my background.js, where i want to collect the list of all installed extensions and return them to the popup to be displayed. In my background.js im calling:

var extensionList = chrome.management.getAll();

which returns nothing, and have also tried

chrome.management.getAll(function(info) {
    alert(info.length);
});

assuming "info" is the array of installed extensions. None of these are working, could anybody point me in the right direction?

Thanks

Dom Shahbazi
  • 720
  • 2
  • 10
  • 25
  • Just to add, i do have "management" set in my manifest permissions – Dom Shahbazi Mar 24 '14 at 16:13
  • The second one (with callback) is correct. (taking a stab in the dark:) Did you use `return true;` in your `chrome.runtime.onMessage` event listener to make sure that `sendResponse` can be called asynchronously to pass the info back? – Rob W Mar 24 '14 at 23:14
  • Sorry im not aware of this concept, could you explain further? im having issues now that getAll() is working, but once i have the list of extensions i need to send them back to another part of my extension. I cant use sendResponse within my getAll() as it is out of scope, but if i call it after getAll() then it does not work as getAll() is a callback. Do you know how i could get round this? thanks – Dom Shahbazi Mar 25 '14 at 12:37
  • 1
    `sendResponse` will work if you add `return true;` at the end of your `onMessage` listener, i.e. `chrome.runtime.onMessage.addListener(function() { ...getAll here and use sendResponse asynchronously...; return true;});` – Rob W Mar 25 '14 at 13:46
  • 1
    Im able to get a response, but im having issues with using getAll(), as my program is moving on from getAll() before it has finished operating on the array of extensions. This results in my function returning an empty array, as the array is returned before getAll() is finished. I could show you code if could help with it? Thanks – Dom Shahbazi Mar 25 '14 at 14:26
  • Sounds like a problem with the flow of your code. It is generally impossible to turn asynchronous code into synchronous code, so you need to restructure your code to make proper use of callbacks. – Rob W Mar 25 '14 at 14:27
  • i basically just need to ensure chrome.management.getAll() gives me a full array of all my extensions before i move on in my code! – Dom Shahbazi Mar 25 '14 at 14:43
  • Indeed, and to do that, you need to restructure your code to accept the array of stuff in an asynchronous way. If you don't know how to do that, do a little bit more of research, or at least put your current code in your question. – Rob W Mar 25 '14 at 14:50
  • I have emailed you if that's okay? Also sent the code I'm referring to. thankyou – Dom Shahbazi Mar 25 '14 at 15:21
  • possible duplicate of [Calling a asynchronous function in a callback](http://stackoverflow.com/questions/22696142/calling-a-asynchronous-function-in-a-callback) – Rob W Mar 28 '14 at 18:43

0 Answers0