Extension Attribute: Get Chrome Extension Version

zachary_fisher
New Contributor III

Hi All,
I have an extension attribute currently that checks for wthether a certain extension in chrome is present. It works beautifully. I was wondering if anyone had a version check extension attribute handy or knew how get one working.

I can see the version in the manifest.json file within the extension directory as well as the folder that the extension lives in, is named its version.

Anyone have any bright idea?

5 REPLIES 5

thegooch49
New Contributor III

I found this in a search, and have the exact same question. My extension attribute retrieves ALL installed chrome extensions. I'm looking to create a smart group based on the version of ONE of these extensions, and ignore the others. Is this a problem someone has solved already?

HUGE thanks for any help.

mm2270
Legendary Contributor III

From what I can see from the one or two Google Chrome extensions I have installed, the version may show up within the path (a folder) to the json file itself. For example, something like nmmhkkegccagdldgiimedpiccmgmieda/1.0.0.4_1/manifest.json where the 1.0.0.4 is the version. The other extension I have installed follows this pattern as well. Something like this might work:

echo "$JSON_FILE" | awk -F'/' '{print $(NF-1)}' | cut -d_ -f1

If it doesn't work to get it from there, and it may not in every case, you can also do something like this, perhaps:

awk -F'"' '/"version":/{print $4}' /path/to/manifest.json

Using the item above and using the full proper path to the json file, it prints out
1.0.0.4

mm2270
Legendary Contributor III

Here's a rough EA that should grab the Chrome Extension name (if available, some of the Google ones just have MSG_APP_NAME in the json, so not so useful) and the version of the extension, and print them together with the name of the user they are installed under.

#!/bin/bash

USER_LIST=$(ls /Users/)

while read User; do
    if [ -d "/Users/$User/Library/Application Support/Google/Chrome/Default/Extensions" ]; then
        EXT_DETAILS=("${User}:")
        EXT_DIRS=$(find /Users/$User/Library/Application Support/Google/Chrome/Default/Extensions -type d -maxdepth 1 -mindepth 1)
        while read EXT; do
            EXT_DETAILS+=("$(awk -F'"' '/"name":|"version":/{print $4}' "$EXT"/*/manifest.json 2>/dev/null | paste - -)")
        done < <(printf '%s
' "$EXT_DIRS")
    fi
done < <(printf '%s
' "$USER_LIST")

printf '%s
' "${EXT_DETAILS[@]}"

thegooch49
New Contributor III

Thanks for the reply @mm2270 . I have something very similar to this already, that returns all of extensions as a string. What I'm looking for, is an integer value return that I can do 'less than' comparisons on, for a specific plug in.

I would want to narrow this down further so the EA returns an integer value for a specific plug in. For example, I would want to look for Reddit Enhancement Suite, and the EA value would return 5.12.5

Huge thanks for the help so far.

mm2270
Legendary Contributor III

@thegooch49 Well, that can be done too. Example. With this, you would need to know the specific folder name that the Google Chrome Extension uses (I believe they are always the same per extension) You would plug that into the variable called "EXTENSION_DIR" and it should print just the version string for that plug-in, if it's installed.

#!/bin/bash

LOGGED_IN_USER=$(stat -f%Su /dev/console)

EXTENSION_DIR="bhloflhklmhfpedakmangadcdofhnnoh"

if [ -e "/Users/$LOGGED_IN_USER/Library/Application Support/Google/Chrome/Default/Extensions/$EXTENSION_DIR" ]; then
    VERSION=$(awk -F'"' '/"version":/{print $4}' "/Users/$LOGGED_IN_USER/Library/Application Support/Google/Chrome/Default/Extensions/$EXTENSION_DIR"/*/manifest.json)
else
    VERSION="0"
fi

echo "<result>$VERSION</result>"

In the above, I'm only looking in the logged in user's folder, but you could use a similar process to my first script that loops over all home directories. Unfortunately, if more than one user has that Extension installed, that would not give you a single integer like what you're looking for.