Send message to background
chrome.runtime.sendMessage({
from: 'content',
subject: 'deleteCcookie'
});
Send message to content
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {
from: 'popup',
subject: 'getSiteInfo'
}, function(info) {
console.log(info);
});
});
AddListener
chrome.runtime.onMessage.addListener(function(msg, sender, response) {
if (msg.from === 'popup' && msg.subject === 'getSiteInfo') {
response({
site: 'weibo',
user: 'moamaoa'
});
}
});
getActiveTab
function getActiveTab(callback) {
chrome.tabs.query({
active: true,
currentWindow: true
}, function(tabs) {
callback(tabs[0]);
});
}
tabs onCreated
chrome.tabs.onCreated.addListener(function(tab) {
console.log(tab)
});
tabs onUpdated
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
console.log(tab)
});
tabs onActivated
chrome.tabs.onActivated.addListener(function(activeInfo) {
getActiveTab(function(tab) {
console.log(tab);
});
});
get cookies
chrome.cookies.get({
name: 'un',
url: 'http://weibo.com/'
}, function(cookie) {
console.log(cookie)
});
chrome.cookies.getAll({
domain: 'weibo.com'
}, function(cookies) {
console.log(cookies)
});
see more: chrome extensions