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

Viewed 122

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!

1 Answers

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

Related