Preheat the oven to 400°F (200°C).
Roll out the puff pastry and fit it into a tart pan.
Prick the bottom of the puff pastry with a fork.
Chill the pastry in the refrigerator for 15 minutes.
In a skillet, heat olive oil over medium heat, then add sliced onions.
Add salt and sugar, stirring frequently for about 30-40 minutes until onions are golden brown.
Remove from heat and let the onions cool slightly.
In a bowl, whisk together heavy cream and eggs.
Add the cooled onions and grated Gruyère to the egg mixture, stirring to combine.
Pour the filling into the prepared pastry shell.
Bake in the preheated oven for 25-30 minutes until set and golden.
Let the tart cool for a few minutes before slicing.
Garnish with fresh thyme leaves before serving.