chrome.tabs.query({}, function(tabs) {
for (i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, 'test');
}
});
chrome.extension.onMessage.addListener(function(message) {
console.log(message);
});
chrome.tabs.query({}, function(tabs) {
for (i = 0; i < tabs.length; i++) {
chrome.tabs.sendMessage(tabs[i].id, 'Привет мир!');
}
});
chrome.extension.onMessage.addListener(function(message) {
console.log('Получено сообщение: ' + message);
});
"permissions": [
"activeTab",
"tabs",
"cookies",
"storage",
"http://*/*",
"https://*/*",
"<all_urls>"
],
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [ "jquery.min.js", "bundle/content.js", "bundle/event.js"],
"run_at": "document_end"
}
],
"background": {
"scripts": ["background.js"],
"persistent": false
},
"web_accessible_resources":[
"main.js",
"bundle/content.js",
"*.svg",
"*.ttf",
"img/*"
]
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
console.log('content');
chrome.runtime.onMessage.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"});
}
);