Preheat oven to 400°F. Lightly spray a 9" x 13" baking dish with nonstick spray, or use butter, and set aside.
In a large skillet over medium-low heat, melt the butter. Then stir in the onion and sauté for about 5 minutes, stirring occasionally, until soft and translucent. Stir in garlic and sauté for 2 more minutes, stirring occasionally. Do not let the onion and garlic brown. Sprinkle flour over the top and stir until evenly combined, then cook for 1 minute.
Slowly pour in chicken stock, whisking gently all the while to combine. Then add milk, salt, pepper, 2 teaspoons of the thyme leaves, and 2 teaspoons of the chopped rosemary; whisk to combine. Cook for 2-3 minutes to bring the sauce to a very gentle simmer; do not let it boil. Sauce should be slightly thickened. Remove skillet from heat.
Add half the potato slices to the bottom of prepared baking dish, in an even layer. With a large slotted spoon, remove all of the onions from the cream sauce and spread them evenly over the potato slices. Drizzle half of the cream sauce over the potatoes and onions. Then sprinkle half of the cheddar cheese over the top, followed by half of the Parmesan. Spread remaining potato slices over the top and drizzle with remaining cream sauce. Sprinkle remaining cheddar and Parmesan over the top.
Cover baking dish tightly with foil and bake for 40 minutes, or until cream sauce is bubbling at the edges. Remove foil and bake for 35-40 minutes, or until potatoes are absolutely tender and cheese is blistered to your liking. If cheese is getting darker than you prefer, lightly tent the baking dish with foil to finish.
Remove baking dish from the oven and sprinkle with a little freshly cracked black pepper, plus the remaining thyme and rosemary. Let sit for 5-10 minutes to settle in. Serve hot/warm.
