Generating differential_fingerprint Value for Chrome Extension Manifest - google-chrome

What does the differential_fingerprint property mean in a Chrome Extension's Manifest V3 file? I could find no reference for it in the docs. I assume it is some kind of hash for authenticity. How does one generate the value of it?

Related

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

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.
Go to chrome://extensions/ and enable Developer mode.
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)!
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:
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)
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.
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.
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.

localStorage limit in Chrome extension

I have a couple of questions on use of localStorage in Chrome extensions.
Is the 5mb storage limit per extension?
Does Chrome use the extension ID to monitor whether an extension conforms to this limit?
In short: Yes and Yes.
localStorage is tied to an origin w3 spec: The localStorage attribute, usually the protocol and host part of a resource's URL.
The origin of a Chrome extension is chrome-extension://EXTENSIONIDHERE, which implies that the extensionID of a Chrome extension is indeed used to enforce the per-origin storage limits.
You can find a proof of this by visiting your profile directory, and looking in the Default/Local Storage directory, which contains several (SQLite) files of the following format:
chrome-extension_EXTENSIONIDHERE_0.localstorage
chrome-extension_EXTENSIONIDHERE_0.localstorage-journal
Extension's localStorage is similar to website's localStorage so I guess it'd be 5mb. You can also consider using chrome.storage
Extension id is the only unique thing to every extension so chrome must use this to conform to this limit.

How I can programatically get the chrome extension ID from a crx file?

I compile the extension using the --pack-extension switch:
C:\Users\APOL0\AppData\Local\Google\Chrome\Application>chrome.exe --pack-extension="D:\MyExt"
Everything works fine: chrome generates Myext.crx and Myext.pem but I don't know how I can get extension ID for automatic installation using Windows' registry.
How can I get this ID without using "manual verification", ie. programatically?
Edit May 14, 2018: Added clarification and link to 3rd party tool.
There is no official supported method (at time of writing) to programmatically get the extension ID from a CRX without manually interacting with Chrome. (See official method below)
Unofficial Method
The only programmatic method I've found any reference to online is on this SO answer. The author of the answer later posted a link to a ChromeIdGenerator tool they wrote to accomplish this. The tool is based on how Chrome calculated its extension IDs at that point. Full disclosure: I have not tested the tool to ensure its accuracy, it is simply the only tool I've found to accomplish what you're asking.
Official Method (manual)
If you open up your Chrome Extensions manager page, you can drag and drop your Myext.crx onto the page (you must be in "Developer Mode") and it will load your extension, showing you the new extension id.

Configure Chrome Extension at Runtime

We're currently building multiple copies of our Chrome CRX, one for each of our dev/test environments, with custom entries in each manifest file.
Often we don't know in advance the hostname of certain test environments prior to building/packaging our code & crx. Is there a way to pass parameters to a Chrome Extension, or have my Extension read its own filename to look for a naming convention etc.
There is no way to pass arguments to CRX or read extension filename, but you can change extension variables in runtime using Developer Tools console.

Chrome extension id - how to find it

How can I find out what the chrome extension id is for an extension?
Use the chrome.runtime.id property from the chrome.runtime API.
You get an extension ID when you upload your extension to Google Web Store. Ie. Adblock has URL https://chrome.google.com/webstore/detail/cfhdojbkjhnklbpkdaibdccddilifddb and the last part of this URL is its extension ID cfhdojbkjhnklbpkdaibdccddilifddb.
If you wish to read installed extension IDs from your extension, check out the managment module. chrome.management.getAll allows to fetch information about all installed extensions.
If you just need to do it one-off, navigate to chrome://extensions. Enable Developer Mode at upper right. The ID will be shown in the box for each extension.
Or, if you're working on developing a userscript or extension, purposefully throw an error. Look in the javascript console, and the ID will be there, on the right side of the console, in the line describing the error.
Lastly, you can look in your chrome extensions directory; it stores extensions in directories named by the ID. This is the worst choice, as you'd have extension IDs, and have to read each manifest.json to figure out which ID was the right one. But if you just installed something, you can also just sort by creation date, and the newest extension directory will be the ID you want.
As Alex Gray points out in a comment above, "all of the corresponding IDs are actually on the extensions page within the browser".
However, you must click the Developer Mode checkbox at top of Extensions page to see them.
Extension IDs can be found in:
chrome://extensions (Chrome_Hotdog >> More_tools >> Extensions) Developer mode.
For Linux: $HOME/.config/google-chrome/Default/Preferences (json file) under ["extensions"].
All extension ID are listed here:
chrome://system