Chrome extension: messaging

CrAppl
CrAppl used Ask the Experts™
on
Hey!

This is not a real extension, I'm just screwing around to see how this works.

Basically, in my background.html page I have this:
function test3()
{
alert("blah3");
chrome.extension.sendRequest('test2');
}

Open in new window


and in my popup.html page, I have this:
chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
        if(request.function == "test3") {
           alert("Works!");
           }
    }
);

Open in new window


But the alert "Works" never seems to be called... I even tried to replace the

 alert("Works!");

Open in new window


with
call_test_function();

Open in new window


which in turn has an alert()... but that does not get called either.

Mind telling me where I went wrong? And giving me the code to make my little example work?

I even reversed the pages so that the code from background is in popup and the code from popup is in background... does not work :(

Thanks! R
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Updating points...
Change:

 if(request.function == "test3")

to

 if(function == "test2")

Author

Commented:
Perfect, thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial