0

Hi there I am trying to undestand how Event Pages work for Chrome extensions. The idea is to ask for the event page to get the bookmarks tree and send it as a response to the popup.

The problem: The response is undefined. The response from the outside of the getTree() function works, the other does not. Am I doing this the wrong way ?

background.js

chrome.runtime.onMessage.addListener(
 function(request, sender, sendResponse) {
   if (request.action == "INIT"){
     chrome.bookmarks.getTree( function( treeStructure ){
       sendResponse(treeStructure);
     });
    }
   //sendResponse(true);
});

popup.js

chrome.runtime.sendMessage({action: "INIT"}, function(response) {
  console.log(response);
});

manifest.xml

{
    "manifest_version": 2,

    "name": "Test",
    "description": "Test",
    "version": "1.0",

    "browser_action": {
        "default_icon": "/img/icon.png",
        "default_popup": "front.html"
    },

    "icons": { "16": "/img/icon.png",
           "48": "/img/icon.png",
          "128": "/img/icon.png" },

    "permissions": [
        "bookmarks",
        "storage",
        "https://*/"
    ],

    "background": {
        "scripts": ["js/back.js"],
        "persistent": false
    }
}
enr00ted
  • 1
  • 2
  • After some more googling around I found something similar [link]https://stackoverflow.com/questions/20077487/chrome-extension-message-passing-response-not-sent . Problem solved by adding return true inside or outside of the IF. – enr00ted May 07 '16 at 08:39

1 Answers1

0

You need to make sure you have the following permission in your manifest file. I can't tell if you have that already, so I'm putting it out there just in case.

"permissions": [
    "bookmarks"
]
Gideon Pyzer
  • 22,610
  • 7
  • 62
  • 68
  • I updated my question, I already have that permission as I am able to get the bookmarks in the background, thing is the message does not get passed to the front/popup. – enr00ted May 06 '16 at 21:32