Avatar of CrAppl
CrAppl

asked on 

Chrome extension: messaging

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
JavaScriptWeb BrowsersScripting Languages

Avatar of undefined
Last Comment
CrAppl
Avatar of CrAppl
CrAppl

ASKER

Updating points...
ASKER CERTIFIED SOLUTION
Avatar of FireAnICE
FireAnICE

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of CrAppl
CrAppl

ASKER

Perfect, thanks!
JavaScript
JavaScript

JavaScript is a dynamic, object-based language commonly used for client-side scripting in web browsers. Recently, server side JavaScript frameworks have also emerged. JavaScript runs on nearly every operating system and in almost every mainstream web browser.

127K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo