com.apple.WebKit.WebContent drops 113 error: Could not find specified service
Asked Answered
S

16

122

I am using WKWebView for viewing custom HTML.

  • Regardless of HTML content, when testing on real device, I receive the following error Could not signal service com.apple.WebKit.WebContent: 113: Could not find specified service in 29 sec after WKWebView content loaded, sometimes I even receive this error twice. Clearly, it is a configuration issue. I have checked cookies as proposed in Could not signal service com.apple.WebKit.WebContent, however it doesn't help
  • Another question is whether there exist a list of all error codes that might pop up in WKWebView
Sucrose answered 16/6, 2017 at 9:41 Comment(4)
Hi @levgen, did you find solution for this problem?Hephzipa
@DragisaDragisic See my comment belowSucrose
Hi, I'm getting this error when using a project generated by Unity, specifically while trying to initialize the ads package. Does anyone know what might be causing this?Underfur
Add "http://" which will solve your problem.Lawless
S
39

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

Sucrose answered 19/6, 2017 at 6:6 Comment(6)
@Nikita, did it help you? Please, share your exp and env. conditions. I am asking since i was planning to remove this comment since it doesn't solve 100% cases why this error can pop up...Sucrose
the log itself happens every time in different cases; I have not found consistent pattern for the log; but the fact of webview addition to the view hierarchy does help to load all of the requests. I had exactly the same case - was not adding a webview to view until it loads; so now I add it to keywindow as hidden in order that it be in view hierarchy, and then, when it loads, I add it to the place it supposed to be and disable hidden property;Mendes
I'm doing what you said in the right order, but I still I get the error. I noticed that the moment it happens seems quite random to me... Like sometimes it happens after I have already dismissed the VC that had the WebView, and some other times it happens when I load it... Have you already figured anything else out?Therontheropod
Thank you this is what I was doing as well and this completely fixes the problem!Conglutinate
Please can i do that " Add WKWebView object to view's subviews array" from a capacitor app (ionic 5)Onia
I don't have loadHTMLString and have this issueFrancoisefrancolin
K
18

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>
Kerplunk answered 14/12, 2017 at 11:28 Comment(2)
This would require a justification in App Store submission as per: developer.apple.com/documentation/bundleresources/…Marrissa
this didn't work for meBiltong
N
17

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.

Naturally answered 22/3, 2018 at 10:10 Comment(2)
I just encountered this and simply running in the simulator without an Xcode debugging session made it go away. There was no Preferences framework or anything else, but it did look like it was related to cookies/localStorage issue in the WKWebView.Strode
You save my days, I have class name Preferences and it stop showing error after I rename it.Nomination
V
9

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.

Vignola answered 7/10, 2017 at 12:54 Comment(2)
Thanks! I was debugging and left off the "s" on the test URL i was using.. this fixed it for me...Brotherson
in my case http:// also worksYoungman
E
8

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

Energid answered 13/8, 2019 at 14:48 Comment(2)
where can i write.. i trid but not playing videoPikeperch
DispatchQueue.main.async { self.wkWebView.loadHTMLString("<html><body font-family:'THSarabun'>Long Live the KING<br/><br/></body></html>", baseURL: nil) }Chorography
C
1

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

Creatinine answered 21/3, 2018 at 7:43 Comment(0)
D
1

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.

Dedication answered 9/10, 2018 at 21:21 Comment(3)
That doesn't seem like a clean solution. I would not like my WKWebView to still exist even after i obviously don't need it anymore because it's using resources and costing a lot of memory.Honniball
I think such thing is called memory leak.Firework
Memory leak, perhaps - but it drove me crazy. I alloc/init only one WKWebView object in the App Delegate, reference that one instance from any view and add it as a subview. Works like a charm. I also set its frame to the frame of a hidden UILabel in the view so I can use all of the Xib resizing.Dedication
C
1

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.

Constabulary answered 26/4, 2019 at 16:56 Comment(1)
Include the actual answer instead of just linking to it.Pius
W
0

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.

Windowsill answered 19/6, 2018 at 5:48 Comment(1)
Removing JavaScript injection fixed the issue for me.... but now I need to find a workaround because i need the JSEvictee
W
0

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!

Wondawonder answered 1/2, 2019 at 13:53 Comment(0)
H
0

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).

Hertzfeld answered 31/5, 2019 at 14:12 Comment(0)
P
0

Deleting/commenting

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

function solved the problem for me.

XCode (11.3.1)

Patristic answered 2/4, 2020 at 20:34 Comment(0)
M
0

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.

Musser answered 9/10, 2021 at 8:49 Comment(0)
Y
0

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

Youngman answered 14/12, 2021 at 9:58 Comment(0)
T
0

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.

Thimerosal answered 6/10, 2022 at 10:44 Comment(0)
E
0

For me, this issue was only happening when running on iOS17 devices/simulators and only when using a WKWebView from Swift Package. On iOS16 it worked fine with package.

Without using package, using xcframework directly copied to Xcode project, everything was working fine.

Echolalia answered 5/1 at 2:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.