There are a few possible answers to this but it ultimately comes back to an evolutionary survival mechanism. When dogs eat grass, they usually throw up right after so they’ve evolved to do this as a mechanism to flush their digestive tract for any poisons they might have ingested. So when you see your dog eating grass, they probably found some plants or flowers that they’re not supposed to eat.

And on a lighter note, they could just be hungry!