There has never been a substitute for circulating behind students to see exactly what they're up to. I had to tell one of mine to get off the meme image site and back to coding today. It's just part of teaching that will unfortunately probably never go away. A supportive school disciplinary structure can help, too. But I realize that's not to be found everywhere.
I hope you are able to work it out successfully.