The following command will dump the dom for a web page using Google Chrome:
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --headless --disable-gpu --dump-dom http://example.com
I'm wondering if something similar is possible for Safari.
I can do this with AppleScript but I'd prefer the solution for Safari to be "headless" (see
--headless option in command above), so I think an AppleScript will not achieve what I'm looking for.
** UPDATE **
Selenium driver has a headless mode for other browsers. But it doesn't look like there is such a mode for safari: https://stackoverflow.com/a/58314435