SFSafariViewController
is compelling, but has a very simple API that doesn't allow setting any fields on the request it initiates when presented. Are there any clever ways to set the HTTP referer header on requests initiated from SFSafariViewController
?
If you want to change the referer (url) header that will be sent to the server when a user clicks an anchor or iframe is opened, you can do it without any hacks. Simply do history. replaceState, you will change the url as it will appear in the browser bar and also the referer that will be send to the server.
The Referer header is set by your browser and sent to the server when you request a page. The value of this header is the URL of the previous page that linked to the newly requested page. It is where you came from, essentially.
This will not work, because browsers don't treat these pages as normal web resources and thus they do not automatically send the "Referer" header when you submit a form.
The Referer HTTP request header contains an absolute or partial address of the page that makes the request. The Referer header allows a server to identify a page where people are visiting it from. This data can be used for analytics, logging, optimized caching, and more.
There is no API for that, unfortunately.
You can check SFSafariViewControllerDelegate page - all of the delegate methods is post-load handlers.
WKWebView and WKNavigationDelegate is one of possible replacements (iOS 8.0+).
The only way I could think to do this would be to bounce the request off of a web service that you control.
Sadly you can't use anything other than http
or https
URLs, so a local file URL won't work (short of listening on a socket on the device).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With