Hi All,
Have a small doubt in how message passing works in chrome using content scrips. I modified the default example (http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/messaging/timer/) for message passing given in the chromium documentation to the one that looks below :
popup.html
function testRequest() {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {counter: "getHTML"}, function handler(response) {
alert("Inside Client = "+response.counter2);
});
});
}
and my content script looks like this :
page.js
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
alert(request.counter);
alert("Inside server .. Req Counter = "+request.counter);
sendResponse({counter2: "5"});
});
When I execute the testRequest from popup.html, the content script is getting called as expected. I do get both the alerts i have
declared with their respective values. But my popup.html response code doesnt seem to be called .. The alert I have inside the popup.html - alert("Inside Client = "+response.counter2);
is not being executed.
On the other hand, If i have a debug point inside the client, its working ! Kinda strange.. Can somebody tell me how and why this is happening ?
Thank you in advance..