Yes, onions should generally be browned before adding tomatoes. Browning the onions develops their sweetness and depth of flavor, which enhances the overall taste of the dish.
Browning onions, also known as caramelizing them, involves cooking them slowly over medium heat until they turn a golden-brown color. This process breaks down the onions' complex sugars, creating a sweeter, richer, and more complex flavor profile. When tomatoes are added before the onions are properly browned, the acidity of the tomatoes can halt the caramelization process. The tomatoes will cook, but the onions will remain relatively raw and sharp in flavor. By browning the onions first, you ensure that they contribute their full potential of flavor to the dish. Start by heating oil or butter in a pan over medium heat. Add the chopped onions and cook, stirring occasionally, until they soften and turn a golden-brown color. This can take anywhere from 10 to 20 minutes, depending on the heat and the amount of onions. Once the onions are browned to your liking, you can then add the tomatoes and continue with your recipe.
Don't overcrowd the pan when browning onions. Overcrowding will steam the onions instead of browning them. Cook in batches if necessary to ensure even browning.