Save and Restore Safari Session (Tabs)

You can certainly do that, e.g. using a periodic trigger or a “focused window” trigger. But this is not the scope of my macro.

But IMHO I’m not sure if it is worth to use a macro for this, since the functionality, as pointed out by @CJK, is already part of the OS, and the session restore via OS fails only in rare cases for you.

Is your Safari crashing often? If yes, then maybe it would be worth to investigate the reason for the crashes (extensions?, …). Currently —on my system— I don’t remember a complete Safari crash for a while. (From time to time a subprocess, likely as part of an open page, is crashing; but this doesn’t bring down the whole Safari.)