Chrome Extension Reporting

MPL
Contributor II

Hello All,

 

Posted something about extensions a couple weeks ago. This request is specifically for Google Chrome extensions.

 

Does anyone have a working EA script that can be used to generate a report on installed Chrome extensions?

 

Sort of like from this request a couple years ago.

- This one currently doesn't work. Tried all the different variations listed on this post.

10 REPLIES 10

sdamiano
Contributor II

If you use Google Workspace, you can use a chrome enrollment token to get reporting direct in the Google Admin console. 

MPL
Contributor II

We currently don't have managed browsers :(. We plan on getting this setup in the near future though. 

 

But until then we've been trying to figure out a way to get a report on all the extensions

cdev
Contributor III

I poked at the old script to try and see if I could get something working. Unfortunately it's a bit of a fragile process as the extensions don't appear to consistently leverage the same tag for the extension name (e.g. appName, extName, extname, name). This might work for you however:

 

 

 

#!/bin/bash

# Setting IFS Env to only use new lines as field seperator 
IFS=$'\n'

currentUser=$( /bin/echo 'show State:/Users/ConsoleUser' | /usr/sbin/scutil | /usr/bin/awk '/Name / { print $3 }' )
lastUser=$( /usr/bin/defaults read /Library/Preferences/com.apple.loginwindow lastUserName )

if [[ "$currentUser" = "" || "$currentUser" = "root" ]]
	then userHome=$( /usr/bin/dscl . -read "/Users/$lastUser" NFSHomeDirectory | awk -F ": " '{print $2}' )
	else userHome=$( /usr/bin/dscl . -read "/Users/$currentUser" NFSHomeDirectory | awk -F ": " '{print $2}' )
fi

createChromeExtList () {
for manifest in "$userHome"/Library/Application\ Support/Google/Chrome/Default/Extensions/*/*/manifest.json
do 
	reportedName=$( grep -i -A 3 "name" "$manifest" | grep "message" | cut -d \" -f4 )
    if [ -f "$( dirname "$manifest")/_locales/en/messages.json" ]; then
        reportedName=$( grep -i -A 3 "name" "$(dirname "$manifest")/_locales/en/messages.json" | grep "message" | cut -d \" -f4 )
    elif [ -f "$( dirname "$manifest")/_locales/en_US/messages.json" ]; then
        reportedName=$( grep -i -A 3 "name" "$(dirname "$manifest")/_locales/en_US/messages.json" | grep "message" | cut -d \" -f4 )
    fi

	version=$(cat $manifest | grep '"version":' | awk -F "\"" '{print $4}')
	extID=$(basename $(dirname $(dirname $manifest)))
	
	# This is the default output style - looks nice in JSS
	# Comment out line below if you wish to use alternate output
	echo -e "Name: $reportedName \nVersion: $version \nID: $extID \n"
	
	# This is the alternate output style - looks ugly in JSS, but possibly more useful
	# Uncomment line below to use this output instead
	#echo -e "$reportedName;$version;$extID"
 done
 } #createChromeExtList


if [ -d "$userHome/Library/Application Support/Google/Chrome/Default/Extensions" ]
    then result="$( createChromeExtList )"
    else result="NA"
fi

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

 

MPL
Contributor II

Hey @cdev,

Thanks for the assistance and getting this code tweaked! I'm getting a result of NA on every EA run though.

 

I tried to change the output path for the extensions from:

$userHome"/Library/Application\ Support/Google/Chrome/Default/Extensions/*/*/manifest.jso

to

$userHome"/Library/Application\ Support/Google/Chrome/Profile\ 1/Extensions/*/*/manifest.json

 

since it wasn't working but can't get that to work either.

MPL
Contributor II

Actually the results are mixed. I'm getting data for some runs and NA for others

cdev
Contributor III

Like I said, it's kinda fragile since not all of the extensions report the name the same way. You also can probably have it iterate through all profiles by changing the line to:

$userHome"/Library/Application\ Support/Google/Chrome/*/Extensions/*/*/manifest.json

MPL
Contributor II

Would I have to update the line towards the bottom as well?

if [ -d "$userHome/Library/Application Support/Google/Chrome/*/Extensions" ]
    then result="$( createChromeExtList )"
    else result="NA"

 

cdev
Contributor III

Changing that to an asterisk will break that statement, as an if can't iterate through all possible entries. Since we're handing the various profiles in the for loop, maybe the best thing to do is change this to:

 

if [ -d "$userHome/Library/Application Support/Google/Chrome" ]

I believe all chrome profiles create an extensions folder by default, so checking further inside the folder shouldn't entirely matter, but it is good practice. As for leaving Default there, unless someone has deleted the 1st/Default profile, it's always there once the app is launched.

MPL
Contributor II

Hey @cdev,

I got this working kinda yesterday! Thank you so much for all your help.

 

Is there a way add something into the code to set a character limit for the name perhaps? Like 50 characters max for instance? Some extension names (like AdBlock Plus) don't output well and it ends up like outputting 100 lines of text.

cdev
Contributor III

It is absolutely possible to limit or adjust what is being output; perhaps this is another case of extensions being made inconsistently and the script is reading/returning the wrong information tag/block, there's a different file to read, or something else. As I mentioned, the script is a bit fragile because of the inconsistencies.