Melt the butter in a large frying pan over medium heat. Add the sliced onion and dried thyme. Cook for 2-3 minutes until the onion softens. Then add the minced garlic and stir for about 30 seconds. Remove the onions from the pan and set aside.
Drizzle the olive oil into the pan and increase heat to medium-high. Add the sliced mushrooms in a single layer. Cook without stirring for 1-2 minutes to help them brown. Stir in the Italian seasoning and balsamic vinegar and continue cooking for another 4-8 minutes, until the mushrooms reduce in volume and most of the liquid evaporates. Allow the mushrooms to brown slightly by avoiding stirring for a brief moment.
Return the sautéed onions and garlic to the pan with the mushrooms. Season with salt and pepper. Remove from the heat and let the mixture cool slightly.
Take the puff pastry out of the fridge. Lightly roll it if needed to form a rectangle. Transfer the pastry onto a baking sheet lined with parchment paper. Score a 1-inch border around the edges with a sharp knife without cutting all the way through.
Prick the center of the dough with a fork a few times to prevent it from puffing up too much. Sprinkle the shredded Gruyère cheese and Parmesan cheese evenly over the pastry, and then spread the cooled mushroom mixture on top.
Brush the exposed border with the beaten egg. Bake in a preheated oven at 375°F for 20-25 minutes, or until the pastry is golden and the filling is set. Let cool slightly before serving. Garnish with chopped parsley.