There appears to be an AppleScript regression in Safari 17.4. References to documents aren’t resolved correctly, so that for example:
name of document 1
Works, but
set d to document 1 name of d
Does not. FB13679244.