In a 2- to 3-quart pan over medium heat, frequently stir onion in butter until limp, 8 to 10 minutes.
Sort cranberries, discarding any soft or decayed fruit; rinse and drain berries. Add cranberries, sugar, vinegar, and cardamom to pan. Cover, reduce heat to low, and stir occasionally until sugar is dissolved and cranberries are translucent, about 20 minutes. Serve warm or cool.