At least for (3), the answer is https://developer.apple.com/documentation/safariservices/safari_web_extensions/messaging_between_the_app_and_javascript_in_a_safari_web_extension
Topic:
Safari & Web
SubTopic:
General
Tags: