1) The "good" solution is to find some work you actually give a shit about. If you can't force yourself to care about corporate software, work on an indie video game, or get a job at Amnesty International, or find some other way to get personally invested in your work product. If you can't find it doing software, become a chef, or build houses, or whatever. It will improve your life immeasurably to spend your day doing something you get intrinsic satisfaction from instead of websurfing.
2) The "bad" solution, more like managing the problem really, is to get good at using Pomodoro timers, to-do lists, and other crutches to force yourself to do enough to not fall behind. "Fall behind" in this context does not mean that you do so little work that everyone notices and calls you out on it, it means that you stop keeping up with new frameworks and new tools and the years march by and your skills atrophy and then your employer folds and you find pushing 50 in an ageist industry with weak skills and few options.
Hope this is helpful.