kasketis / netfox

A lightweight, one line setup, iOS / OSX network debugging library! 🦊
MIT License
3.68k stars 374 forks source link

Facebook Audience Network requests can't be logged #103

Closed mhillebrand closed 2 years ago

mhillebrand commented 7 years ago

I love Netfox, but I'm unable to see requests made to *.facebook.com from Facebook's FAN SDK:

https://origincache.facebook.com/developers/resources/?id=FBAudienceNetwork-4.26.1.zip

It's a dynamic framework, so I'm not sure how their HTTP requests are being made exactly. Any ideas?

Thanks, Matt

mhillebrand commented 7 years ago

I did some disassembling of the FAN framework with Hopper and found that it relies on WKWebView, and then I verified with Xcode's visual debugger that each FAN ad lives within an instance of WKWebView, which means NSURLProtocol won't work with FAN requests.

I did some Googling and found some interesting workarounds:

Since not all of my users will be on iOS 11, I converted the first solution to Swift, but I'm still not seeing FAN requests with Netfox:

extension NFXProtocol {
    public class func wk_registerScheme(_ scheme: String) {
        guard let contextController = NSClassFromString("WKBrowsingContextController") as? NSObjectProtocol else { return }
        let selector = Selector(("registerSchemeForCustomProtocol:"))

        if contextController.responds(to: selector) {
            _ = contextController.perform(selector, with: scheme)
        }
    }

    public class func wk_unregisterScheme(_ scheme: String) {
        guard let contextController = NSClassFromString("WKBrowsingContextController") as? NSObjectProtocol else { return }
        let selector = Selector(("unregisterSchemeForCustomProtocol:"))

        if contextController.responds(to: selector) {
            _ = contextController.perform(selector, with: scheme)
        }
    }
}
Janglinator commented 6 years ago

This seems like a lot more testing needs to happen

Janglinator commented 6 years ago

I added a WKWebView to the sample project. We can use this for testing the proposed solution. I haven't gotten a chance to write an actual fix yet though

vGubriienko commented 2 years ago

Closing this as already make task in project for that https://github.com/kasketis/netfox/projects/1#card-76856365