Cook the Spaghetti: Bring a large pot of salted water to a boil. Add uncooked spaghetti and boil for 8–10 minutes, or until al dente (follow package instructions for timing). Drain, rinse under cold water to halt cooking, and set aside. (Skip this step if using pre-cooked leftover spaghetti.)
Caramelize the Onions: Heat olive oil in a large ovenproof nonstick skillet over medium heat. Add chopped onions and cook, stirring occasionally, until golden brown and tender (10–12 minutes). Transfer onions to a bowl and let cool slightly. Wipe the skillet clean with a paper towel.
Prepare the Egg Mixture: In a large mixing bowl, whisk together eggs and milk until fully combined. Stir in Parmesan cheese, parsley, basil, salt, pepper, and the cooled caramelized onions. Add cooked spaghetti and toss gently to coat the noodles evenly in the egg mixture.
Cook the Frittata: Generously coat the cleaned skillet with nonstick cooking spray and place over medium heat. Pour in the egg-spaghetti mixture, spreading it into an even layer. Cook undisturbed for 3–5 minutes, rotating the skillet occasionally to ensure even browning, until the bottom is golden and set.
Flip and Finish Cooking: Carefully invert a large plate over the skillet. Using oven mitts, grip the plate and skillet firmly and flip them together to transfer the frittata onto the plate. Re-spray the skillet with cooking spray, then slide the frittata back into the pan, uncooked side down. Cook for an additional 3–4 minutes, until the bottom is golden and the center is fully set.
Serve: Slide the frittata onto a serving platter. Garnish with diced tomato, if desired. Slice into wedges and serve warm, at room temperature, or chilled.