1

I am building a safari app extension that will redirect certain requests through a local proxy.

For example https://tracking-script.com/track/user/123 needs to be redirected http://localhost:9000

The only problem that I do not know what domains are bad during application bootstrap. My bundle includes: 1. MacOS app to host safari extension and content blocker 2. Safari extension where I can performance certain actions 3. Content Blocker which basically gives rules to Safari during application bootstrap https://www.infoq.com/articles/safari-content-blockers/

Is it possible to dynamically inspect a request and redirect it through a given port?

I have a device on my local network that gives me these rules. So if a page requests https://tracking-script.com/track/user/123 I first want to consult with my device running on localhost. If the response from the device says this domain is bad I want my content blocker to redirect this request to http://localhost:9000 instead of going to the original URL.

Is this even possible in Safari/MacOS? I can do this in chrome and firefox extensions by hooking up on the onBeforeRequest hook. I make a request to my device and if the device says the domain is bad then I returned {redirect_url: 'http://localhost:9000'} and the browser redirects this request.

Tony
  • 174
  • 1
  • 6

1 Answers1

0

You can try intercepting the HTTP request in the content script and then redirect the request to localhost if request. More details are given in this post.

geri-m
  • 665
  • 2
  • 11
  • 23