I suffered from the problems you describe, grabbing a browser window or my phone which would usually take my attention much longer than the task and it left me burned out at the end of the day.
There are some helper tools, like blocking "interesting" pages (like HN, reddit) on the browser, putting the phone in the bag at the end of the room or using a pomodoro timer so sequence proper breaks. But at the end the only thing that really helped is getting into meditation: I try to use these little interruptions of flow as a opportunity to bore myself. Try to reframe boredom from being an annoyance that needs to be fought to a chance to relax your brain for a couple of seconds and refocus.
The want to grab the phone is hard at the start, but it gets better very soon when you manage to push through the discomfort in the first days.