It’s normal for potatoes to slowly start turning brown once they’ve been grated and exposed to oxygen. To prevent this, grate the onion first, so you can mix the grated potato through it straight away.