WebContent 丢失113错误: 无法找到指定的服务

我使用 WKWebView查看自定义 HTML。

  • 不管 HTML 内容如何,在实际设备上测试时,在加载 WKWebView内容后的29秒内,我会收到以下错误 Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service,有时我甚至会收到两次这样的错误。显然,这是一个配置问题。我已经检查了在 无法通知服务 com.apple. WebKit. WebContent中建议的 cookie,但是它没有帮助
  • 另一个问题是,是否存在 WKWebView中可能弹出的所有错误代码的列表
150081 次浏览

Finally, solved the problem above. I was receiving errors

  • Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service

Since I have not added WKWebView object on the view as a subview and tried to call -loadHTMLString:baseURL: on the top of it. And only after it was successfully loaded I was adding it to view's subviews - which was totally wrong. The correct solution for my problem is:

1. Add WKWebView object to view's subviews array

2. Call -loadHTMLString:baseURL: for recently added WKWebView

I got this error loading a http:// URL where the server replied with a redirect to https. After changing the URL I pass to WKWebView to https://... it worked.

I too faced this problem when loading an 'http' url in WKWebView in iOS 11, it is working fine with https.

What worked for me was setting App transport setting in info.pist file to allow arbitary load.

<key>NSAppTransportSecurity</key>
<dict>
<!--Not a recommended way, there are better solutions available-->
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

SWIFT

Well I did this in the following order and didn't get any error like Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service after that, following code might help you too.

webView = WKWebView(frame: self.view.frame)
self.view.addSubview(self.view.webView)
webView.navigationDelegate = self
webView.loadHTMLString(htmlString, baseURL: nil)

Do as order.

Thanks

Maybe it's an entirely different situation, but I always got WebView[43046:188825] Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service when opening a webpage on the simulator while having the debugger attached to it. If I end the debugger and opening the app again the webpage will open just fine. This doesn't happen on the devices.

After spending an entire work-day trying to figure out what's wrong, I found out that if we have a framework named Preferences, UIWebView and WKWebView will not be able to open a webpage and will throw the error above.

To reproduce this error just make a simple app with WKWebView to show a webpage. Then create a new framework target and name it Preferences. Then import it to the main target and run the simulator again. WKWebView will fail to open a webpage.

So, it might be unlikely, but if you have a framework with the name Preferences, try deleting or renaming it.

Also, if anyone has an explanation for this please do share.

BTW, I was on Xcode 9.2.

Mine was different again. I was setting the user-agent like so:

    NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];

This was causing something on the web page to freak out and leak memory. Not sure why but removing this sorted the issue for me.

In my case I was launching a WKWebView and displaying a website. Then (within 25 seconds) I deallocated the WKWebView. But 25-60 seconds after launching the WKWebView I received this "113" error message. I assume the system was trying to signal something to the WKWebView and couldn't find it because it was deallocated.

The fix was simply to leave the WKWebView allocated.

Perhaps the below method could be the cause if you've set it to

func webView(_ webView: WebView!,decidePolicyForNavigationAction actionInformation: [AnyHashable : Any]!, request: URLRequest!, frame: WebFrame!, decisionListener listener: WebPolicyDecisionListener!)

ends with

decisionHandler(.cancel)

for the default navigationAction.request.url

Hope it works!

On OS X, it's necessary to make sure Sandbox capabilities are set-up properly in order to use WKWebView.

This link made this clear to me: https://forums.developer.apple.com/thread/92265

Sharing hoping that it will help someone.


Select the Project File in the Navigator, select Capabilities, then make sure that:
* App Sandbox is OFF,
OR
* App Sandbox is ON AND Outgoing Connections (Client) is checked.

Just for others reference, I seemed to have this issue too if I tried to load a URL that had whitespace at the end (was being pulled from user input).

I had this problem I iOS 12.4 when calling evaluateJavascript. I solved it by wrapping the call in DispatchQueue.main.async { }

Deleting/commenting

- (void)viewWillAppear:(BOOL)animated {[super viewWillAppear:YES];}

function solved the problem for me.

XCode (11.3.1)

I tried almost everything, my solution was simple, updating MacOS to the latest version, and also Xcode to the latest version, that way the error was gone, white blank screen was not happening anymore.

Just check your URL that you are passing to load request, I was receiving same error when I came to this page, later checked that I was getting URl starting from "www" Later I added "https://" , it works for me

For those who use flutter, I get the same error on webview_flutter, flutter_inappwebview and flutter_webview_plugin which I thought its from the package so I tried different things. However, in my case I was trying to open customer scheme URL to use it to open the app which is something like appname://code=xxx... and the WKWebView won't allow you to open it, but on Android it will be opened but you'll get some error message.

It was working fine on flutter_webview_plugin cause it does provider onUrlChange listener which will intercept the call before loading it and allow you to do what you want with it... for me, I closed the webview and used url_luncher.

To do the same thing on webview_flutter you should use the navigationDelegate option to allow opening the URL or not, as follows:

WebView(
javascriptMode: JavascriptMode.unrestricted,
initialUrl: url,
navigationDelegate: (x) {
if(x.url.toString().toLowerCase().startsWith('appname://')){
//close webview and do something
// prevent open the url
return NavigationDecision.prevent;
}
else return NavigationDecision.navigate;
},

For flutter_inappwebview there is an option they mention on the official doc ... I didn't try it cause webview_flutter did work... but I suppose it does the same thing

resourceCustomSchemes: List of custom schemes that the WebView must handle. Use the WebView.onLoadResourceCustomScheme event to intercept resource requests with custom scheme.