For the pastry, sift the flour into a mixing bowl and add a pinch of salt. Add the butter and rub together with your fingertips until the mixture resembles breadcrumbs and all the butter is combined.
Add one to two tablespoons of water and mix to bring the mixture together as a dough. If it seems too dry add another tablespoon of water. Form into a ball and flatten into a disc, wrap in clingfilm and leave it to rest in the fridge for half an hour.
Preheat the oven to 180C/350F/Gas 4.
For the filling, heat a large heavy-based frying pan or saucepan over a medium heat. Add the butter and, once melted, stir in the onions along with a pinch of salt. Reduce the heat to medium low and cook the onions for 20-30 minutes, or until golden-brown and completely softened. Stir them often and make sure that none burn or stick to the bottom of the pan. Stir in the thyme.
Remove the pastry from the fridge and roll out until the thickness of a £1 coin. Grease a 20cm/8in or 23cm/9in tart tin with butter and line the tin with the pastry, pressing it into the edges. Place in the preheated oven and bake for 10 minutes. Remove, brush the base and inside edges with a little of the beaten egg, place back in the oven for five minutes and then remove.
Mix the remaining beaten egg with the cream and cooked onions. Season with a pinch of salt and pepper. Spoon the onion mixture into the pastry case and spread evenly.
Place back into the preheated oven and cook for 30-35 minutes, or until the filling is set but with a slight wobble when poked. Remove from the oven and leave to cool for 10 minutes before slicing into wedges and serving. This is also delicious cold.