3

In a traditional UIWebview, we can easily inject javascript into the web page loaded within the web view.

Is there a way to do this in SFSafariViewController?

SFSafariViewController works great for my needs because it can access cookies and I need this to allow an already authenticated user to access a web site. But my native iOS app has to be able to fill in form fields within the loaded web page. The native app will be responsible for launching the device camera and scanning a barcode, then injecting the barcode text back into specific field on the web page. I can easily do this if I can just inject javascript into the Safari View.

Any thoughts? Is this something that is restricted? I cannot find any info on this.

thanks

Jesse
  • 2,674
  • 6
  • 30
  • 47
  • You could research using a custom `NSURLProtocol`. This can be used to intercept and handle all traffic that goes to/from a normal `UIWebView`, but I don't know if this will allow you to see and handle the traffic from a `SFSafariViewController`, or if that traffic happens outside of the sandbox of the app. But it's worth looking into. If I had to guess, though, I would assume it won't work, because this would basically allow someone to get private data from a user's web browser cookies and stored passwords without the user knowing. – Gavin Apr 07 '16 at 19:59
  • 1
    If you just want to inject some data, why not route it through the URL? i.e. mydomain.com/path?data=yourdata – Zorayr Apr 22 '16 at 05:15

0 Answers0