Get a List of Google Chrome Extensions

falbrecht
New Contributor III

I have seen a few posts about getting a list of Chrome extensions installed but have not had any luck. Does anyone know of a way to generate a report of installed Chrome extensions?

1 ACCEPTED SOLUTION

mario
New Contributor III

Add that script as an extension attribute, and all your Macs will update their inventory with this information during future inventory updates. You could then make an advanced computer search of all Macs with non-blank values for this EA and export the list to get a report of hostnames, and optionally include the full list of Chrome extensions installed in your report.

View solution in original post

14 REPLIES 14

mario
New Contributor III

falbrecht
New Contributor III

Thanks for the response Mario!

Yeah I saw that and was able to run that on a test machine but do you have any ideas on how to generate a report against all computers in Jamf pro using this? We have around 200 machines and can't think of another way besides going to all the individual computer policy histories and grabbing that info manually.

mario
New Contributor III

Add that script as an extension attribute, and all your Macs will update their inventory with this information during future inventory updates. You could then make an advanced computer search of all Macs with non-blank values for this EA and export the list to get a report of hostnames, and optionally include the full list of Chrome extensions installed in your report.

falbrecht
New Contributor III

Awesome that worked! Thank you Mario very helpful!

vcparra
New Contributor

Hi @mario - there are a few scripts in that link you posted. Like @falbrecht, I am looking for one that will generate a report of installed Chrome extensions. Do you mind posting which exactly worked? I appreciate your help. Thanks!

mario
New Contributor III

The above is an anchor link that jumps directly to emily’s extension attribute which has been extremely reliable for me. The other scripts are  variations that modify the output format, but you should be able to try them out on your own Mac to validate them and pick your favorite formatting (or modify the script to output differently).

vcparra
New Contributor

@mario Thanks! Using the one anchored (below), what would the value be set to in the creation of the EA?

 

#!/bin/bash

loggedInUser=`python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "
");'`

JSONS=$( find "/Users/${loggedInUser}/Library/Application Support/Google/Chrome/Default/Extensions/" -maxdepth 4 -name "manifest.json" )

while read JSON; do
    NAME=$( awk -F'"' '/name/{print $4}' "$JSON" )
    if [[ ! -z "$NAME" ]] && [[ ! "$NAME" =~ "_MSG_" ]]; then
        EXTS+=( "${NAME}
" )
    fi
done < <(echo "$JSONS")

echo "<result>$(echo -e "${EXTS[@]}")</result>"

 

mario
New Contributor III

It’ll be the list of extensions installed in Google Chrome for the current logged-in user. Give it a try on your Mac!

Might recommend reaching out in the original thread if you have questions about the script’s functionality. I didn’t write it, I just shared it. 😁

vcparra
New Contributor

I understand the script does that but I guess my question is, how do i use this script/where do I put the script? Add as an extension attribute? But then how do I produce the list of extensions installed for the current logged-in user.

I don't understand how to use the script in Jamf.

mario
New Contributor III

Ah, gotcha. You’ll want to add the script to Jamf Pro under Extension Attributes. Product docs should point you in the right direction.

vcparra
New Contributor

Yep, I got that far but it still doesnt answer the question of ultimately, how and where do I get the final list? Do I make it a Smart Group, but what would the "value" be under criteria for the script?

Chrome Extension Installed Script (EA) IS {value}

OR is there another method I am unaware of?

mario
New Contributor III

Yep, you’ve got it! Make a smart group using the new EA as criteria. Once you add the EA you’ll get a good sense of the formatting; should be one EA title per line, so LIKE {extension name} would probably be the best setup looking for specific extensions.

Separately: you should join MacAdmins Slack! It’s a bit more efficient to get help on how to use Jamf Pro in a chat channel full of knowledgeable helpful people than in forum replies to one person.

lonjee
New Contributor

After a few hours of troubleshooting why the above is not working for our users, we modified the original script to account for different profiles on the machine as well as cleanly formatting the results. Still need to parse out what extension belongs to which profile, but this should help others that are struggling to find the solution as I had. 

Then just follow the setup for the EA and reporting as needed!

 

#!/bin/bash
loggedInUser=`/bin/ls -l /dev/console | /usr/bin/awk '{ print $3 }'`

EXTS=()

for profile_folder in /Users/$loggedInUser/Library/Application\ Support/Google/Chrome/Profile*/; do
    JSONS=$( find "$profile_folder" -maxdepth 4 -name "manifest.json" )

    while read JSON; do
        NAME=$( awk -F'"' '/name/{print $4}' "$JSON" )
        if [[ ! -z "$NAME" ]] && [[ ! "$NAME" =~ "_MSG_" ]]; then
            if [[ ! " ${EXTS[@]} " =~ " ${NAME} " ]]; then
                EXTS+=( "${NAME}" )
            fi
        fi
    done < <(echo "$JSONS")
done

JSONS=$( find "/Users/$loggedInUser/Library/Application Support/Google/Chrome/Default/Extensions/" -maxdepth 4 -name "manifest.json" )

while read JSON; do
    NAME=$( awk -F'"' '/name/{print $4}' "$JSON" )
    if [[ ! -z "$NAME" ]] && [[ ! "$NAME" =~ "_MSG_" ]]; then
        if [[ ! " ${EXTS[@]} " =~ " ${NAME} " ]]; then
            EXTS+=( "${NAME}" )
        fi
    fi
done < <(echo "$JSONS")

RESULTS=""
for ext in "${EXTS[@]}"; do
    found=false
    for profile_folder in /Users/$loggedInUser/Library/Application\ Support/Google/Chrome/Profile*/; do
        if [[ -f "$profile_folder/Extensions/$ext/manifest.json" ]]; then
            if [ -n "$RESULTS" ]; then
                RESULTS+=$'\n'
            fi
            RESULTS+=$(basename "$profile_folder").${ext}
            found=true
            break
        fi
    done
    if ! $found; then
        if [ -n "$RESULTS" ]; then
            RESULTS+=$'\n'
        fi
        RESULTS+=$ext
    fi
done

RESULTS=$(echo "$RESULTS" | tr -cd '[:alnum:]\n')

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

 

 

milce99
New Contributor

Posting a script that will retrieve the list of installed extension IDs on a device and then directly fetch the names of the extensions from the Chrome Web Store. While testing other scripts, it was observed that not all installed extensions will be listed.

The script will perform a check for all Chrome profiles, eliminate duplicate names from the final list (in case the same extension is installed under multiple profiles), and exclude any extensions that are not found in the Chrome Web Store.

I simply required a comprehensive list of all extensions on the device and did not need to differentiate between profiles. List format can be improved to remove dashes but this was good enough for needed reports.

 

 

#!/bin/bash

# Script to retrieve extracted URLs from Chrome extensions in multiple directories

# Get the currently logged-in user
loggedInUser=$(stat -f "%Su" /dev/console)

# Specify the base directory for Chrome profiles
base_directory="/Users/$loggedInUser/Library/Application Support/Google/Chrome"

# Array to store extracted URLs
response_urls=()

# Check if the "Default" directory exists
if [ -d "$base_directory/Default" ]; then
  default_extensions_directory="$base_directory/Default/Extensions"

  # Find the directories in the Default extensions directory
  default_sub_directories=$(find "$default_extensions_directory" -type d -mindepth 1 -maxdepth 1 -exec basename {} \;)

  # Loop through each sub-directory in Default
  for directory in $default_sub_directories; do
    url="https://chrome.google.com/webstore/detail/$directory"

    # Make a request and retrieve the response URL
    response_url=$(curl -Ls -o /dev/null -w "%{url_effective}" "$url")

    # Exclude the response URL if it's the same as the input URL
    if [ "$response_url" == "$url" ]; then
      continue
    fi

    # Extract the desired part of the URL between 'detail/' and '/'
    extracted_url=$(echo "$response_url" | awk -F 'detail/' '{print $2}' | awk -F '/' '{print $1}')

    # Add the extracted URL to the array
    response_urls+=("$extracted_url")
  done
fi

# Loop through each profile directory using wildcard
for profile_folder in "$base_directory/Profile"*/; do
  extensions_directory="$profile_folder/Extensions"

  # Check if the extensions directory exists
  if [ ! -d "$extensions_directory" ]; then
    continue
  fi

  # Find the directories in the extensions directory
  sub_directories=$(find "$extensions_directory" -type d -mindepth 1 -maxdepth 1 -exec basename {} \;)

  # Loop through each sub-directory
  for directory in $sub_directories; do
    url="https://chrome.google.com/webstore/detail/$directory"

    # Make a request and retrieve the response URL
    response_url=$(curl -Ls -o /dev/null -w "%{url_effective}" "$url")

    # Exclude the response URL if it's the same as the input URL
    if [ "$response_url" == "$url" ]; then
      continue
    fi

    # Extract the desired part of the URL between 'detail/' and '/'
    extracted_url=$(echo "$response_url" | awk -F 'detail/' '{print $2}' | awk -F '/' '{print $1}')

    # Add the extracted URL to the array
    response_urls+=("$extracted_url")
  done
done

# Remove duplicates from the array
response_urls=($(printf "%s\n" "${response_urls[@]}" | sort -u))

# Output the result in the desired format for Jamf Pro
IFS=$'\n'
echo "<result>$(echo "${response_urls[*]}")</result>"