Detect navigator inside WebExtension's manifest.json

274 views Asked by At

I am currently working on a WebExtension and I have a small problem. On my Firefox browser I'm able to import and run my work without any error/warning. However with Google Chrome I have a big warning about a feature not implemented (the browser_style property of manifest.json key options_ui).

I'd like to create something like an if statement based on the navigator name to not set this property on Chrome but keep it on Firefox.

Here is the part of my manifest.json:

"options_ui": {                                                                                                                                                                    
"page": "contents/settings.html",                                                                                                                                              
"browser_style": true                                                                                                                                                       
},

And here is what I'd like to have (not working):

"options_ui": {                                                                                                                                                                    
"page": "contents/settings.html",
if (options_ui.browser_style) {                                                                                                                          
    "browser_style": true      
    }                                                                                                                                                 
},    

Any ideas on how to create a condition like this in a manifest.json file?

1

There are 1 answers

3
Makyen On

As Daniel Herr implied in a comment, the manifest.json file is straight JSON formatted data. JSON has no capability to run code. There is no possibility to dynamically define properties within your manifest.json file. You have 2 options:

  1. Live with the warning(s).
    Both Chrome and Firefox have valid properties defined for manifest.json files which the other does not support. Both show warnings when there are unsupported properties. These are only warnings and do not cause the browser to prevent the extension from running. Chrome prominently shows these in chrome://extensions/. Firefox shows them in the Browser Console (Ctrl-Shift-J, or Cmd-Shift-J on OSX).
  2. Have a separate manifest.json file per browser.
    This adds some complexity to your build/development process, but will allow you to eliminate these warnings in each browser.

Note: Even if you don't submit different manifest.json files to Google (Chrome Web Store - Extensions) and Mozilla (AMO), by the time the extension package is distributed to the user, the manifest.json files and other contents of the extension package will be different, as the process of going from submission to distribution results in that file being modified and/or additional files being added to the extension package.