Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency: runtime.getManifest() and missing keys #400

Open
bershanskiy opened this issue May 31, 2023 · 7 comments
Open

Inconsistency: runtime.getManifest() and missing keys #400

bershanskiy opened this issue May 31, 2023 · 7 comments
Labels
inconsistency Inconsistent behavior across browsers

Comments

@bershanskiy
Copy link
Member

bershanskiy commented May 31, 2023

Background

runtime.getManifest() lets extensions to retrieve their own manifest.json contents (Chrome docs, MDN). At least in principle, since the retrieved data structure is actually a result of export of browser-internal data structure generated from manifest.json and other sources. This ticket aims to clarify the differences and reconciliate them.

Details

Availability

runtime.getManifest() availability in different contexts differs across browsers. In Chromium and Firefox, chrome.runtime.getManifest() exists in content script contexts, but in Safari it does not.

Using null or undefined for empty fields

Chromium and Safari use missing values (which do not appear in Object.keys() list and evaluate to undefined). Firefox uses null.

Manifest current_locale member

Chromium adds current_locale to manifest. Firefox does not. Safari 16.5 does not.

Manifest update_url

Chromium seemingly hides update_url.

Other differences?

@tophf
Copy link

tophf commented Jun 3, 2023

Adding an example for an "empty field" and a "missing value" would be helpful as these aren't precise terms in extensions/JS.

@Rob--W Rob--W added the follow-up: chrome Needs a response from a Chrome representative label Jun 22, 2023
@xeenon xeenon added inconsistency Inconsistent behavior across browsers and removed needs-triage labels Feb 29, 2024
@oliverdunk
Copy link
Member

I spoke to @rdcronin about this. We are generally aligned that chrome.runtime.getManifest() should return the browser's parsed version of the manifest including any extra fields added during distribution such as update_url. In Chrome, we also return it after any keys using the __MSG format have been localized. It would be interesting to know if other browsers do the same.

In Chromium and Firefox, chrome.runtime.getManifest() exists in content script contexts, but in Safari it does not.

This matches our expectation, and we don't plan to remove this API from content scripts.

Using null or undefined for empty fields

I'm not certain what is meant here. Is it just that fields not specified by the developer aren't included?

Manifest current_locale member

This is an implementation detail, and part of how we store which language we have localized the manifest (and fields like name) to. It shouldn't be returned and we need to filter this out - great spot. I've filed a bug: https://issues.chromium.org/350350583

Chromium seemingly hides update_url.

I wasn't able to reproduce this - are you still seeing it?

@oliverdunk oliverdunk removed the follow-up: chrome Needs a response from a Chrome representative label Jul 1, 2024
@xeenon
Copy link
Collaborator

xeenon commented Jul 1, 2024

Safari also localizes the result, so you should not see any __MSG values.

@fregante
Copy link

fregante commented Jul 1, 2024

I recently found out that Firefox does not return the manifest verbatim but it drops anything it doesn't support, that includes any items in the permissions array. An example is "contextMenus" on Firefox Android. Safari iOS limits itself to leaving browser.contextMenus undefined, but Firefox removes all mentions from the manifest too.

@carlosjeurissen
Copy link
Contributor

carlosjeurissen commented Jul 3, 2024

@oliverdunk Seems the current_locale property of chrome.runtime.getManifest() always returns the equivalent locale given by chrome.i18n.getMessage('@@ui_locale'), even if the extension is not localised in said language. So this property seems pretty useless in it's current form. @hanguokai this might be relevant for #641.

@hanguokai
Copy link
Member

@hanguokai this might be relevant for #641.

Oliver has replied to current_locale before. He said "it shouldn't be returned". I also think so, because it does not exist in the manifest file.

Back to this issue itself, there are some inconsistencies due to the lack of specifications. However, from a developer's perspective, I don't know of any real-world cases where developers have to rely on this method. Basically, manifest is just static data.

In the meeting note, @bershanskiy said "Sometimes it's convenient to use this as feature detection for support of manifest keys.". If so, I think it would be better to provide a new method for it, such as runtime.support().

@birtles
Copy link

birtles commented Jul 5, 2024

Another difference is that Safari appears to append the unique install ID to the end of manifest.version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
inconsistency Inconsistent behavior across browsers
Projects
None yet
Development

No branches or pull requests

9 participants