Preheat the oven to 375°F (190°C). Unroll the pastry crust and press it gently into a 9-inch tart pan. Prick the bottom with a fork and chill in the refrigerator while preparing the filling.
Melt the butter in a large skillet over medium heat. Add the sliced onions and cook for 5-7 minutes until they begin to soften.
Add the sliced leeks to the skillet. Continue to cook for another 8-10 minutes, stirring occasionally, until both the leeks and onions are tender and lightly caramelized. Remove from heat and let cool slightly.
Spread the cooked leek and onion mixture evenly over the bottom of the prepared pastry crust.
Sprinkle the freshly grated Gruyere cheese over the leek and onion layer.
In a medium mixing bowl, whisk together the heavy cream, eggs, salt, and black pepper until smooth and well combined.
Carefully pour the egg and cream mixture over the vegetables and cheese in the tart shell.
Bake in the preheated oven for 35-40 minutes, or until the filling is set in the center and the top is a beautiful golden brown.
Remove the tart from the oven and allow it to cool in the pan for 10-15 minutes before slicing and serving.