I know that, if I wanted to grep for a pattern only on files with certain extensions, I could do this:
// searches recursively and matches case insensitively in
if you want to search across all branches, you can use the following:
git log -Sres --all --name-only -- '*.js'
(I see you specify git grep; to me the approach here seems simpler and easier to remember--more like other operations I need commonly.)