DEV Community

panfan
panfan

Posted on • Originally published at manon.icu on

Chrome插件开发 - Hooking into installs

当你想为用户提供一些额外信息的时候

当你想在用户卸载的时候触发某个操作

当你希望在更新的时候重定向到更改日志

扩展 hooks 将非常有必要

在浏览器扩展中捕获onInstall操作

打开public/background.js

chrome.runtime.onInstall.addListener((details) => {
  // do something
})
Enter fullscreen mode Exit fullscreen mode

触发onInstall的可能操作

  • install
  • update
  • chrome_update
  • shared_module_update

以下代码展示了捕获安装和更新的动作

chrome.runtime.onInstalled.addListener((details) => {
  if (details.reason === 'install') {
    chrome.notifications.create({
      type: 'basic',
      iconUrl: 'icons/icon-48.png',
      title: 'Hi there 👋',
      message: 'Welcome to the best extensions you ever installed',
      buttons: [{title: 'Thanks 😅️'}],
      priority: 0
    })
  }

  if (details.reason === 'update') {
    chrome.notifications.create({
      type: 'basic',
      iconUrl: 'icons/icon-48.png',
      title: 'Thank you',
      message: 'For updating this extensions',
      buttons: [{title: 'Cool'}],
      priority: 0
    })
  }
})
Enter fullscreen mode Exit fullscreen mode

当你想在用户卸载的时候,可以重定向到某个 url

chrome.runtime.onInstalled.addListener(details => {
    chrome.runtime.setUninstallURL('https://manon.icu/');
}
Enter fullscreen mode Exit fullscreen mode

Source Code

【Source Code】

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more