Created
April 21, 2011 03:54
-
-
Save anonymous/933685 to your computer and use it in GitHub Desktop.
Message Passing attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
chrome.tabs.getSelected(null, function(tab) { | |
chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function(response) { | |
console.log(response.farewell); | |
}); | |
}); | |
</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chrome.extension.onRequest.addListener( | |
function(request, sender, sendResponse) { | |
console.log(sender.tab ? | |
"from a content script:" + sender.tab.url : | |
"from the extension"); | |
if (request.greeting == "hello") | |
sendResponse({farewell: "goodbye"}); | |
else | |
sendResponse({}); // snub them. | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Test", | |
"version": "1.0", | |
"background": "background.html", | |
"permissions": [ | |
"tabs", "http://*/*" | |
], | |
"content_scripts": [ | |
{ | |
"matches": ["http://*/*"], | |
"js": ["content_script.js"] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment