如何更改 chrome 打包的应用程序 ID 或者为什么我们需要 manifest.json 中的关键字段? [英] How to change chrome packaged app id Or Why do we need key field in the manifest.json?

本文介绍了如何更改 chrome 打包的应用程序 ID 或者为什么我们需要 manifest.json 中的关键字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一次性 chrome 钱包付款为 chrome 商店开发打包应用程序.对于我的应用,我需要在运行时检查用户是否购买了应用,或者不决定它是演示功能还是完整功能.

根据 chrome 上的在线演示并选择您的 crx 文件刚刚创建(同样:只需打开控制台即可查看密钥"和扩展 ID).

当您准备好将应用/扩展程序提交到 Chrome 网上应用店时,请按照以下步骤操作:

  1. 创建一个包含扩展的 zip 文件(重要:manifest.json 必须位于根目录,即directory/manifest.json"是坏的,manifest.json"是好的).
    • 将 .pem 文件添加为 key.pem
      (这是保留扩展 ID 所必需的)
  2. 将扩展程序上传到 Chrome 网上应用店(ma​​nifest.json 中没有key"字段,CWS 将拒绝任何包含key"字段的上传).

对于后续更新,不应将key.pem"添加到 zip 文件中,因为 Chrome Web Store 不再需要它.

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.

解决方案

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:

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.

这篇关于如何更改 chrome 打包的应用程序 ID 或者为什么我们需要 manifest.json 中的关键字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆