How to change chrome packaged app id Or Why do we need key field in the manifest.json?
K

3

66

I'm developing packaged app for chrome store using one-time chrome wallet payments. For my app I need to check during the runtime if user bought the app or not to decide should it be demo functionality or full functionality.

According to the chrome identity API documentation :

to keep application ID constant, You need to copy the key in the installed manifest.json to your source manifest.

I have 2 questions about this procedure:

1) under what condition the id of my application may change? I've tried to re-install the app and made updates but the apps id remains the same.. If there is no way to change apps id than why do I need this procedure for?

2) how can I upload my zip archive with manifest.json (which contains "key" field) to chrome dashboard? The problem is that uploader throw an error at me:

An error occurred: Failed to process your item.

key field is not allowed in manifest.

Kuhlmann answered 1/2, 2014 at 12:3 Comment(1)
"under what condition the id of my application may change?" The id generated when a key is not present seems to only change if the path to the unpacked extension changes, and is also different for each system (prob user names in paths). I expect this is a more painful issue for extension dev in team settings (reqs maintaining many auth domains). I prefer not to use a key so the dev extension appears at the top of the list and also I can toggle dev vs production extension via enable/disable instead of uninstalling/installing.Roxannroxanna
R
165

Once uploaded to the Chrome Web Store, your extension ID is fixed and cannot be changed any more.

The ID is derived from the .pem file that was created the first time you (or the Chrome Web Store) packed the extension in a .crx file. When you load an extension in "unpacked mode", an ID is automatically generated in an unpredictable way. The only way to control the extension ID during development is by setting the "key" field in the manifest file, as the documentation suggests.

When you have already published the extension in the Chrome Web Store, then you can easily get the value of this "key" field using the Chrome Extension Source Viewer. After installing the extension, go to your Chrome web store details page and click on the CRX button to view the source. When the Chrome Extension Source viewer has loaded the extension, it will display the key in the console, which can directly be copy-pasted to your manifest.json:

Screenshot: Public key (paste into manifest.json to preserve extension ID) crxviewer.js:528 "key": "....", crxviewer.js:529 Calculated extension ID: jifpbeccnghkjeaalbbjmodiffmgedin

If you have not published your extension, or you do not want to use the Chrome Web Store, then you need to generate a private key first.

  1. Go to chrome://extensions/ and enable Developer mode.
  2. Click on "Pack extension...", select your app/extension's directory and confirm.
    Now you've got a .crx file and a .pem file. Back up the private key (.pem file)!
  3. The extension mentioned can be used to get the same information. Alternatively, visit the online demo at https://robwu.nl/crxviewer/ and select the crx file you've just created (again: just open the console to see the "key" and extension ID).

When you're ready to submit your app/extension to the Chrome Web Store, follow the following steps:

  1. Create a zip file containing your extension (important: manifest.json must be at the root, i.e. "directory/manifest.json" is bad, "manifest.json" is good).
    • Add the .pem file as key.pem!
      (this is necessary to preserve the extension ID)
  2. Upload the extension to the Chrome Web Store (without the "key" field in manifest.json, the CWS will reject any upload that contains a "key" field).

For subsequent updates, "key.pem" should not be added to the zip file, because the Chrome Web Store does not need it any more.

Rialto answered 1/2, 2014 at 16:44 Comment(12)
@Qvatra The .pem file created by Chrome contains your private key. Its corresponding public key is used as input to calculate the extension ID. The contents of a CRX file is signed with the private key, and the signature is inserted in the CRX file header. The purpose of the signature is to ensure integrity, Chrome will refuse to install CRX files whose signature is invalid. Since it's (almost) impossible to forge the signature without the private key, you should not loose it.Rialto
I am having trouble finding the "key" value to set during development. It seems that Chrome Apps are not stored in the /Extensions/... folder like a normal extension. Does anyone know where to find it?Hilaire
If loaded in unpacked mode, then the file will be at the extension source. In other cases, it can be found at Default/Extensions. If you still cannot find the file, search for manifest.jsonRialto
GOOD ANSWER. I reach this question/answer from this link (github.com/dropbox/dropbox-js/issues/200)which is also helpfulCellaret
Since the CRX Viewer can calculate the key and the ID solely on the contents of the .crx file, that means there is a chance that two independent developers get the same ID if they were generated initially from some minimalistic extension (like I did).Sweetener
@RobW what happens if you upload an update of the extension in the Web Store with the "key" field added in the manifest file? it worked for maintaining the same id during development, I didn't remove it from manifest and upload a new version and I think the local storage data was reset. Do you have any info about this?Grimaldi
@Grimaldi I have never tried to upload an extension with a "key" field. I think that it is unconditionally overwritten by the CWS, based on the provided key.pem (auto generated if needed).Rialto
For some reason the local extension didn't calculate the key for me. But this link did robwu.nl/crxviewer (same extension online)Dipole
So what's the best way to go about developing a published extension? Just add the key field while developing and remove it before publishing any updates?Molybdous
I don't think CWS rejects if the key is present. It rejects if it is an incorrect form. developer.chrome.com/extensions/manifestRydder
Updated doc link: manifest v2 developer.chrome.com/docs/extensions/mv2/manifest/key and manifest v3 developer.chrome.com/docs/extensions/mv3/manifest/keyPrimine
no longer seems to work, fi (2023)Bushel
D
11

Hopefully somebody can give a better answer than me. An app's id is generated by google when you first upload it to the web store. However, it's not the same id that you have when developing locally. Your chrome browser generated some other id using some other mechanism.

When you are developing locally from your source code directory as an unpacked extension, and you want to use the id that the chrome web store assigned to your app, you put the "key" in your manifest and reload your app. This helps you because many APIs expect chrome.runtime.id (the id of your app) to be the same value as the app in the store. You can leave the "key" in your manifest and it will be ignored.

Dread answered 1/2, 2014 at 15:30 Comment(1)
What do you mean by developing locally? is it when you upload app not via a dashboard but via menu/tools/extensions option in a chrome? Am I understand you correct that key field is needed to reproduce actual apps id in store while you testing your app via menu/tools/extensions?Kuhlmann
E
1

For anyone having problem loading the unpacked extension with the key field in the manifest.json file.

Remove your published extension if you have it in your extension list but disabled. Since otherwise your local dev extension won't load and no error will be shown. The reason being that chrome detects duplicate keys for the extension and ignores it silently.

Egwin answered 19/10, 2018 at 19:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.