Chrome extension snippets
Apr 1, 2016 · 1 分钟阅读

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

← Previous Post Next Post →

Ryun的博客
与其感慨路难行,不如马上出发。

atom css design git html javascript jekyll laravel life mac mobile optimization sublime tool vscode vue
mac

About

你好,❤朋友

这里是 Ryun 的博客 📝

📝记录了我学习 🔎的过程

作为一名前端攻城狮 🦁

希望能和大家一起 🔎

共同进步 🏃

🦁的特长:

  • HTML5
  • CSS3
  • JavaScript
  • Vue.js
  • 微信小程序
  • 熟练配合 Node.js、PHP 和 Laravel
  • 熟练使用各种开发和设计工具

🦁喜欢 🆒🆒的东西

对提升效率和美感的事物有兴趣 😋

欢迎 👏交流


see this hugo-theme-dream-ink