This worked great for me using "Execute JavaScript For Automation" as the action. I removed the last line throw e;
so if the action was fired without any notifications present the code completes instead of erroring.
Created a new macro here. Clear Notifications - Big Sur - Macro (v9.1)
Thanks!