Ads by Google

How to Get manifest.json Objects Inside Chrome Extension?

Many times developers like myself struggling with certain problems. On one extension on which I work I find myself in the problem of how to get manifest.json informations, ie manifest.json objects and its results.

Searching on Google I figureout that all depends on the Chrome version. After Crome version 22.0.0.0 there is available object  chrome.runtime where you can get also manifest informations using object chrome.runtime.getManifest. But what if users don’t use new versions of Chrome and don’t want to update it?

One solution is to place in your manifest.json property like "minimum_chrome_version" : "22.0.0.0" what will force users to use new version of Chrome.

Second solution can be writting function that can support all Chrome versions and allow users to use your extension in all Chrome versions.

The second solution is better for me and I made one function what will share with you.

Extract manifest.json Objects

This function using simple check if chrome.runtime.getManifest exists or not exists. If exists, function return objects from direct chrome.runtime object but if not exists, I using simple XHR request to get manifest.json  file and transform JSON data to objects to can access inside all values.

Here is the code:

Simple, right?

You can use this function like this:

And you will get version from your extension inside your code.

With this code you can get anything from manifest.json and also you can name it how you want.

Cheers 😉

Summary
How to Get manifest.json Objects Inside Chrome Extension?
Article Name
How to Get manifest.json Objects Inside Chrome Extension?
Description
If you have a problem to get manifest .json objects inside Chrome extension, here is the best solution to get manifest.json objects inside Chrome extension.
Author
www.CreativForm.com