Весь день я пытаюсь заставить это работать, но ничего.Почему, скажите мне, пожалуйста, почему это # @! *> Не хочет работать?
Manifest.json
{
"name": "My First Extension",
"version": "1.0",
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"popup": "popup.html"
},
"permissions": [
"tabs"
],
"content_scripts": [
{
"matches" : ["http://*/*"],
"js": ["contentscript.js"]
}
]
}
popup.html
<script src="contentscript.js"></script>
<script>
function get(){
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.
});
}
get();
</script>
contentscript.js
function send(){
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
}
send();
Это показывает мне:
Uncaught TypeError: Cannot call method 'getSelected' of undefined
Uncaught TypeError: Cannot read property 'onRequest' of undefined