'Is there any way to get an applescript to constantly run in the background, ideally launching when Safari launches?' - no, there is not a way to have an AppleScript applet running in the background, and then be launched (since it is already launched) when a process (such as 'Safari') starts. You cannot launch something that is already launched - unless, you are referring to a daemon or thread, which AppleScript does not do.
However, you can save an AppleScript as an application (thus the name - AppleScript 'applet'). To have the applet run all the time (when opened [launched, run]), in 'Script Editor's 'Save' / 'Save As...' menu item's sheet make sure to click on the 'Stay Open' check box (to add a check mark).
To have the code in the 'applet' check, for 'Safari', every x seconds - use ...
return x -- where x is the number of seconds to check again
... as the last line in the 'on idle' handler.
For example, ...
on run
idle
end
on idle
-- your code here
return 30 -- the 'idle ()' handler executes infinitely every 30 seconds.
end idle