Defend King Side Attack
Hi!
Here are a few small tips :
-Rooks like open files. When on the defense, never let your opponent get their rooks into open files!
-Try to close up the position if you have a chance, closed positions result in solid structures.
-When on the defense, try to trade as many pieces as you can. The less pieces your opponent has to attack with, the more successful your attack will be.
You can also try the "defense" puzzles at chess.com's detailed puzzle section!
If you're only going to play with a couple pieces against almost the entire army of your opponent, you're facing an uphill battle.
Leave your knight on f3. That's a great defender
He had both bishops, a knight, his queen, and his rook bearing down on your castled position. You didn't have defenders once your knight left. That's pretty overwhelming odds.
Try to only move each piece once in the beginning until all your pieces are out and your rooks are connected. That is, there is no other piece between your rooks on the back rank.

Yikes! What a game. This is called the Stafford Gambit (a well known, not often played -- except in blitz or to catch people off guard, variation of Petrov Defense), and it leads to some nasty traps for white. If you haven't seen it before, don't feel too bad.
And for what it's worth, I really haven't learned it either. But looking at the chess database here, it seems that in Masters games that have reached your position after four moves, white has played: d3, Nc3, e5, or f3. As you can see, each of those has a direct purpose: either developing a piece, protecting your e4 pawn, or attacking black's knight. Your move, however, Be2 doesn't really do any of those things. (Bishops often like to start off on the 3rd, 4th, or 5th ranks, but sometimes the second rank is called for).
I'll note one thing -- you said that your problem "constantly" happens to you. Can you share such a game that's *not* Petroff's Defense?
But, still, you had some saving moves. 9. e5 would have helped. If the queen takes the pawn, then you have 10 Bxg4
Yikes! What a game. This is called the Stafford Gambit (a well known, not often played -- except in blitz or to catch people off guard, variation of Petrov Defense), and it leads to some nasty traps for white. If you haven't seen it before, don't feel too bad.
And for what it's worth, I really haven't learned it either. But looking at the chess database here, it seems that in Masters games that have reached your position after four moves, white has played: d3, Nc3, e5, or f3. As you can see, each of those has a direct purpose: either developing a piece, protecting your e4 pawn, or attacking black's knight. Your move, however, Be2 doesn't really do any of those things. (Bishops often like to start off on the 3rd, 4th, or 5th ranks, but sometimes the second rank is called for).
I'll note one thing -- you said that your problem "constantly" happens to you. Can you share such a game that's *not* Petroff's Defense?
But, still, you had some saving moves. 9. e5 would have helped. If the queen takes the pawn, then you have 10 Bxg4
stafford is fun

Yikes! What a game. This is called the Stafford Gambit (a well known, not often played -- except in blitz or to catch people off guard, variation of Petrov Defense), and it leads to some nasty traps for white. If you haven't seen it before, don't feel too bad.
And for what it's worth, I really haven't learned it either. But looking at the chess database here, it seems that in Masters games that have reached your position after four moves, white has played: d3, Nc3, e5, or f3. As you can see, each of those has a direct purpose: either developing a piece, protecting your e4 pawn, or attacking black's knight. Your move, however, Be2 doesn't really do any of those things. (Bishops often like to start off on the 3rd, 4th, or 5th ranks, but sometimes the second rank is called for).
I'll note one thing -- you said that your problem "constantly" happens to you. Can you share such a game that's *not* Petroff's Defense?
But, still, you had some saving moves. 9. e5 would have helped. If the queen takes the pawn, then you have 10 Bxg4
+1

The opening of the game you played is a Stafford Gambit. You lost to a common trap. You should watch some videos on youtube about the Stafford gambit. For example Eric Rosen's videos and the Daniel Naroditsky video about refuting it.
There's a great (free) analysis of it, all written out (not videos) at https://lichess.org/study/c9YhCd5b and https://lichess.org/study/L2fAfOer (I think the first one is more in depth, not sure)

The most thematic reply to an attack on the flank is a counter-attack in the center.
The center of a chess-board is like the top of a hill. Pieces there can dominate the surrounding terrain and make it hard for the opponent to move about freely.
One of the WORST ways to reply to an attack on the flank is to push Pawns on that side of the board. What were you thinking when you played 7. h3?
Try meeting that flank attack with counter-play in the center: