简体   繁体   中英

How can I test chrome.runtime.onInstalled for a Chrome extension?

I would like to know if there is a way to test the chrome.runtime.onInstalled handler. Basically I'm working on a chrome extension that uses the chrome storage to save certain data in memory. However in my new release version I would like to make changes to the data model of the chrome storage. For that reason I guess I need to write a migration file that fires when the old version is updated to the new chrome version und migrate the data.

chrome.runtime.onInstalled.addListener((details => {
  if (details.reason === 'update') {
    console.debug(`Upgrading from version ${details.previousVersion}`)
    const previousVersion = parseVersion(details.previousVersion || '0.0.0')
    if (compareVersions(previousVersion, [1, 1, 0]) <= 0) {
      upgradeFrom1_1_0()
    }
  }
}))

I want to use onInstalled for this something like above, but I wonder if there is any way I can properly test this. Does anyone have an idea? Any suggestions are appreciated, thanks!

You have to create two distinct crx files. These are the steps:

  1. Create the.crx file for the older versior and save.pem file apart
  2. Drag the.crx file on chrome://extensions/ page and confirm the installation
  3. Create the.crx file for the newer versior using the just saved.pem file
  4. Drag this latter.crx file on chrome://extensions/ page and open the devtool console to check the update.

Remember : Some browsers no longer allow installation from crx files. There are two ways to solve this nuisance. I tell you the fastest way. Install SRWare Iron browser which still allows this type of installation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM