astro:page-load

In Astro, DOMContentLoaded doesn’t reliably work, so you should use the astro:page-load event instead.

Helpful: astro:page-load docs