wkwebviewconfiguration

Making WKWebView not share cookies with Safari in OS X

守給你的承諾、 提交于 2019-12-04 08:50:12
How do I make WKWebView not share cookies with Safari in OSX? I have a very simple app that I made as an experiment that displays a WKWebView and as far as I can see, it's picking up cookies from Safari, because in my custom app, I'm logged in in the same websites as Safari. I am currently creating the WKWebView instance like this: override func loadView() { self.webView = WKWebView() self.view = self.webView! } in an NSViewController I created. I also tried this: override func loadView() { var processPool = WKProcessPool() var config = WKWebViewConfiguration() config.processPool = processPool

Capturing window.print() from a WKWebView

自闭症网瘾萝莉.ら 提交于 2019-12-04 06:10:58
I'm trying to capture the window.print() javascript call from a WKWebView with my app to actually show a print dialog and allow them to print from a button presented on the page (instead of a button inside my app). Does anyone know the best way to accomplish this? Currently, for me, clicking a link that calls window.print() just does nothing but fire the decidePolicyForNavigationAction delegate method and I couldn't find anything relevant in there. Figured it out just after posting (obviously)... Hopefully this helps someone else. When creating your web view... let configuration =

WKWebview getAllCookies crash in iOS 11.3

回眸只為那壹抹淺笑 提交于 2019-12-04 03:36:29
We have recently migrated to WKWebview. We have added a listener for cookie change, to get the updated cookies and update our own store. - (void)cookiesDidChangeInCookieStore:(WKHTTPCookieStore *)cookieStore { [cookieStore getAllCookies:^(NSArray* cookies) { }]; } Once the controller is loaded, it calls cookiesDidChangeInCookieStore and crashes at "getAllCookies".But this crash happens only in TestFlight/Fabric build. Doesn't happen when i run the app directly on device from xcode (both in debug and release mode). Below is the crash report, Thread 9 name: WebThread Thread 9 Crashed: 0 WebKit

How to check if WkWebView finish loading in Objective-C?

﹥>﹥吖頭↗ 提交于 2019-12-03 22:05:44
I want to load HTML pages using WkWebView and I want to show the page just after it's finished loading. As long as it's loading I would like to show an activity indicator on an empty View. I create two view a loadingView and a wkWebView. While the page is loading I add to VC as subview the loadingView and after I want to remove loadingView and add wkWebView. Here is my code: [self addSubview:_loadingView]; _wkWebView = [[WKWebView alloc] initWithFrame:self.frame]; _wkWebView.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height); //Send a

Why INSPECT ELEMENT or WEB INSPECTOR or developerExtrasEnabled (WkWebView) is not working in iOS While its working for OSX

☆樱花仙子☆ 提交于 2019-12-02 10:56:19
Here is the code snippet that facilitates the INSPECT ELEMENT in WkWebView preferences.setValue(true, forKey:"developerExtrasEnabled") Here is the screenshot of INSPECT ELEMENT working in OSX(right click) Right click is equivalent to Tap & Hold in iOS But I am not able to see anything like I see in OSX Here is the complete code if anybody wants to try Its not possible to do in iOS as WKPreference is not key value coding-compliant for the key developerExtrasEnabled so we can't do this using this approach. 来源: https://stackoverflow.com/questions/34927983/why-inspect-element-or-web-inspector-or

WKWebView only showing desktop site

筅森魡賤 提交于 2019-12-02 05:36:19
问题 I just migrated from UIWebView and my new WKWebView will only show the desktop version of the site I'm loading. My UIWebView showed the responsive site appropriately. I have tried forcing a mobile User-Agent and confirmed that it is coming in on to the server let userAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) Mobile/11A465 Twitter for iPhone" webView.customUserAgent = userAgent Does anyone have any other ideas I can try? Thanks 回答1:

WKUserScript not working

佐手、 提交于 2019-12-01 17:31:19
I want to inject a script using WKWebview API. For some reason it isn't working and I can't figure it out. I've tried debugging in Safari developer console and I can't find the JavaScript code in there either. Implementation Code as follows: NSString *js = @"document.body.style.background = \"#FF0000\";"; NSString *myScriptSource = @"alert('Hello, World!')"; WKUserScript *s = [[WKUserScript alloc] initWithSource:myScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart forMainFrameOnly:YES]; WKUserContentController *c = [[WKUserContentController alloc] init]; [c addUserScript:s];

WKUserScript not working

放肆的年华 提交于 2019-12-01 17:06:53
问题 I want to inject a script using WKWebview API. For some reason it isn't working and I can't figure it out. I've tried debugging in Safari developer console and I can't find the JavaScript code in there either. Implementation Code as follows: NSString *js = @"document.body.style.background = \"#FF0000\";"; NSString *myScriptSource = @"alert('Hello, World!')"; WKUserScript *s = [[WKUserScript alloc] initWithSource:myScriptSource injectionTime:WKUserScriptInjectionTimeAtDocumentStart

WKWebview evaluateJavascript is not working, throws an error

孤者浪人 提交于 2019-11-30 08:06:20
问题 I am trying to call an existent function from a remote site in a WKWebview: function addtext (text) { jQuery("#webviewtest").html(text); } With: [self.WebView evaluateJavaScript:@"addtext(\"This is a text from app\");" completionHandler:^(id Result, NSError * error) { NSLog(@"Error -> %@", error); }]; But this is throwing an error: Error Domain=WKErrorDomain Code=4 "A JavaScript exception occurred" UserInfo=0x170c788c0 {NSLocalizedDescription=A JavaScript exception occurred} This is so simple

Capturing window.print() from a WKWebView

筅森魡賤 提交于 2019-11-30 05:44:43
问题 I'm trying to capture the window.print() javascript call from a WKWebView with my app to actually show a print dialog and allow them to print from a button presented on the page (instead of a button inside my app). Does anyone know the best way to accomplish this? Currently, for me, clicking a link that calls window.print() just does nothing but fire the decidePolicyForNavigationAction delegate method and I couldn't find anything relevant in there. 回答1: Figured it out just after posting