Introduction
We load a saved web archive (NSData) into a WKWebView instance using following method:
[self.webView loadData: archive
MIMEType:@"application/x-webarchive"
characterEncodingName:@""
baseURL:baseURL];
We also have some custom scripts injected safely into the web view using following snippet
WKUserScript *userScript = [[WKUserScript alloc] initWithSource:<jsfilename> injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:onMainFrame];
[webview.configuration.userContentController addUserScript:userScript];
Things work fine till here.
Observation
When I get the call from Javascript Layer to the native iOS Layer via:
-[CustomWebViewController userContentController:didReceiveScriptMessage:]
the value message.frameInfo.request.URL.absoluteString
is "about:blank"
Question
Is there any way to get the original baseURL back here?
Alternatives Considered:
Store the baseUrl
in an instance variable and use it here but since we are using this url to determine if the request is coming from valid domains, having a url from this method will be most credible.
We are looking a way to piggyback this info (baseURL domain) to our web archive at the time of loading it in webView and extract that from the -[CustomWebViewController userContentController:didReceiveScriptMessage:]
method
Any help will be much appreciated.