Background:
I am working on a network privacy product. Basically I have a device that intelligently blocks requests from all device on your network if it determines that the request is not privacy friendly. i.e. google services, facebook, other ads services are blocked.
Problem:
I am building a safari extension which will let a user whitelist a page. i.e. user uses facebook heavily and some things don't work on facebook because lots of requests are blocked because they are deemed to be unsafe by the device. In this case the user does not care and from the safari extension the user can whitelist facebook.com. Now the device knows that the user has whitelisted facebook, but it doesn't know what extenal domains are called by facebook, so my safari extension needs to intercept requests to determine if they originated from a tab where facebook.com is loaded. For example googleads.com/marketing/ads. My device has a way to allow requests to go through it without blocking; and that's basically anything that goes through port 9999. In this case the safari extension needs to append port 9999 to the request making it googleads.com:9999/marketing/ads
In chrome and firefox extension I can easily hook up to the onBeforeRequest event and redirect the request via port 9999 (googleads.com:9999/marketing/ads). However I can't seem to intercept a request on a Safari app extension. I've been researching Content Blocker extensions as well, but it seems like you can only give a set of rules for blocking and only during bootstrap, it does not happen to intercept every request.
Questions:
Is it possible to accomplish what I've described above (intercepting requests and redirecting them through another port) in a safari app extension? If so what's the best way to accomplish this?
Thank you