{"action":"created","issue":{"url":"https://api.github.com/repos/AliSoftware/OHHTTPStubs/issues/179","repository_url":"https://api.github.com/repos/AliSoftware/OHHTTPStubs","labels_url":"https://api.github.com/repos/AliSoftware/OHHTTPStubs/issues/179/labels{/name}","comments_url":"https://api.github.com/repos/AliSoftware/OHHTTPStubs/issues/179/comments","events_url":"https://api.github.com/repos/AliSoftware/OHHTTPStubs/issues/179/events","html_url":"https://github.com/AliSoftware/OHHTTPStubs/issues/179","id":157993628,"number":179,"title":"Unable to stub WKWebview?","user":{"login":"trilorez","id":3771859,"avatar_url":"https://avatars.githubusercontent.com/u/3771859?v=3","gravatar_id":"","url":"https://api.github.com/users/trilorez","html_url":"https://github.com/trilorez","followers_url":"https://api.github.com/users/trilorez/followers","following_url":"https://api.github.com/users/trilorez/following{/other_user}","gists_url":"https://api.github.com/users/trilorez/gists{/gist_id}","starred_url":"https://api.github.com/users/trilorez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trilorez/subscriptions","organizations_url":"https://api.github.com/users/trilorez/orgs","repos_url":"https://api.github.com/users/trilorez/repos","events_url":"https://api.github.com/users/trilorez/events{/privacy}","received_events_url":"https://api.github.com/users/trilorez/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2016-06-01T19:58:57Z","updated_at":"2016-06-02T01:04:44Z","closed_at":"2016-06-02T01:04:44Z","body":"I'm having issues attempting to stub WKWebview. \r\n[Here's a simple test project](https://github.com/AliSoftware/OHHTTPStubs/files/294255/WebViewTest.zip).\r\nI added a catch-all stub in the `AppDelegate`. The stub test block gets called but the response block is never called. Digging a little deeper, I see that `OHHTTPStubsProtocol` `initWithRequest:cachedResponse:client:` is never called, even though `canInitWithRequest:` returns `true`. Does `WKWebview` not support stubbing or am I missing something?\r\n"},"comment":{"url":"https://api.github.com/repos/AliSoftware/OHHTTPStubs/issues/comments/223169326","html_url":"https://github.com/AliSoftware/OHHTTPStubs/issues/179#issuecomment-223169326","issue_url":"https://api.github.com/repos/AliSoftware/OHHTTPStubs/issues/179","id":223169326,"user":{"login":"AliSoftware","id":216089,"avatar_url":"https://avatars.githubusercontent.com/u/216089?v=3","gravatar_id":"","url":"https://api.github.com/users/AliSoftware","html_url":"https://github.com/AliSoftware","followers_url":"https://api.github.com/users/AliSoftware/followers","following_url":"https://api.github.com/users/AliSoftware/following{/other_user}","gists_url":"https://api.github.com/users/AliSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/AliSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AliSoftware/subscriptions","organizations_url":"https://api.github.com/users/AliSoftware/orgs","repos_url":"https://api.github.com/users/AliSoftware/repos","events_url":"https://api.github.com/users/AliSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/AliSoftware/received_events","type":"User","site_admin":false},"created_at":"2016-06-02T01:04:44Z","updated_at":"2016-06-02T01:04:44Z","body":"Ok after a little digging, I can confirm that it is indeed a limitation of `WKWebView`.\r\n\r\nSee for example [this answer in SO](http://stackoverflow.com/questions/24208229/wkwebview-and-nsurlprotocol-not-working) but also [this radat](https://openradar.appspot.com/radar?id=5253455685877760) as well as [this one](http://www.openradar.me/24231298). As `OHHTTPStubs` uses an `NSURLProtocol` behind the scenes to catch the outgoing requests transparently and return the stubs before they hit the network, then `WKWebView` not supporting custom `NSURLProtocol` classes means we'll never be able to catch those requests from the application.\r\n\r\nThis is all because `WKWebView` uses an out-of-process engine to send requests, execute JS and render the page, and is totally isolated from the app process. So we have very little control over `WKWebView` for this sort of things (they have the same problem about cookies and similar features btw)\r\n\r\nI'm going to close this issue now, as this is actually an Apple Bug and I won't be able to do anything about it, but feel free to open a bug report to Apple (by duplicating the radars I mentioned above) to make this possible one day… hopefully!"}}
{"actor":{"display_login":"AliSoftware"}}