One situation where they can be good: if you have a space advantage. Often if White has a space advantage, he doesn't want to trade pieces, so stopping a bishop coming to g4 and pinning the knight, with the idea of trading next turn, might be a good idea.
Another situation is if the squares in the centre need the control of a piece ie. if Black's strategy is to control the dark squares like d4 and e5 and White protects them with a knight on f3, then Black might often play Bg4 to try and exchange off the knight. Here's an example of that:
I've heard that masters think that pushing the far pawns forward, defensively, to prevent attacks from the bishop and knight to the center a waste of tempo.
They show that attacks like fried liver can be prevented in other ways (in a well-ordered opening), I guess by castling or by pushing a pawn up to fork the bishop and pawn of the opponent and trade your knight for their bishop (pxp, bxk, qxb). But the latter can lead to some messy and risky conflicts. And sometimes I pull the opposite knight out instead so I'm stuck doing H3, when the threat of fried liver looms.
When are those corner pawn moves a good idea and when are they just a waste of time?