For any reason, for tech support to show a bug in realtime or for any other reason.
macOS: QuickTime is built In and does It from File > New Screen Recording. While quicktime is doing that you may not be able to click menus you select or open with the mouse, so use the Up/Down arrow keys if you need to navigate an open menu.
Windows: Windows has no built in screen recorder but there are lots of apps that do that. OBS is arguably the best free choice: https://obsproject.com/
Licecap is also good for either platform for animated gifs: https://www.cockos.com/licecap/