Prevent MacOS from locking screen when you disconnect screen sharing

I screenshare into a Mac for playing video on my TV, and had an intermittent problem where Firefox would not play video while screen sharing was connected, but then locked the screen as soon as I disconnected.

It turns out that if the screen is locked when you log in via screensharing, MacOS defaults to locking it again when you disconnected, and, being MacOS, the ability to turn this off has been removed from the UI.

Enter this in terminal to turn it off: sudo defaults write /Library/Preferences/com.apple.RemoteManagement RestoreMachineState -bool NO