I\'m currently updating a userscript to a chrome extension, but since the new ID is different it won\'t update the old extension, but add a new one.
Is there a way t
Userscripts are converted to Chrome extensions when you load it. Follow these steps to create and maintain an extension with the same ID:
chrome://extensions/
and activate developer mode.@version
).--user-data-dir=...
flag, then visit ...
./tmp/
or %tmp%
.Okay, steps 6-7 are optional, they were only included to show that a userscript is converted to a true extension, with a special flag set. You can also notice the red warning about the manifest version. To fix that, edit manifest.json
, and add "manifest_version": 2,
. So, in our case:
...
"converted_from_user_script": true,
"description": "Description of user script",
"key": "eYxnPzfSPtfL3ji4nQX3ujTXpzz3YQ6dVlvHWf1gvW8=",
"name": "Userscript",
"version": "1.0",
"manifest_version": 2
}
Now, you've got a Chrome extension which behaves like a Chrome extension with some extra flavour. Follow the steps from the official documentation to update your package:
Updating a package
To create an updated version of your extension:
- Increase the version number in
manifest.json
.- Bring up the Extensions management page by going to this URL: chrome://extensions
- Click the Pack extension button. A dialog appears.
- In the Extension root directory field, specify the path to the extension's folder—for example,
c:\myext
.- In the Private key file field, specify the location of the already generated
.pem
file for this extension—for example,c:\myext.pem
.- Click OK.
Uploading a previously packaged extension to the Chrome Web Store
You can use the Chrome Developer Dashboard to upload an extension that you've previously packaged yourself. However, unless you take special steps, the extension's ID in the Chrome Web Store will be different from its ID in the package you created. This different ID might be a problem if you've distributed your extension package, because it allows users to install multiple versions of your extension, each with its own local data.
If you want to keep the extension ID the same, follow these steps:
- Rename the private key that was generated when you created the
.crx
file tokey.pem
.- Put
key.pem
in the top directory of your extension.- Compress that directory into a ZIP file.
- Upload the ZIP file using the Chrome Developer Dashboard.
The extensionID of an extension can be controlled via the "key" parameter in the manifest file. The easiest way to have the same ID for the unpacked and packed extension is also stated in the documentation:
key This value can be used to control the unique ID of an extension, app, or theme when it is loaded during development.
Note: You don't usually need to use this value. Instead, write your code so that the key value doesn't matter by using relative paths and chrome.extension.getURL().
To get a suitable key value, first install your extension from a .crx file (you may need to upload your extension or package it manually). Then, in your user data directory, look in the file
Default/Extensions/
. You will see the key value filled in there./ /manifest.json
When the key
field does not exists, it's randomly generated. Then, the extensionID is generated from this key. The algorithm for generating the extensionID is explained here. By the nature of the algorithm, you cannot perform it in the reverse order (extensionID -> key
).