Skip to content

moodlemobile/cordova-plugin-wkwebview-cookies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

title description
WKWebView Cookies
Plugin to manage cookies in WKWebView (iOS).

cordova-plugin-wkwebview-cookies

Plugin to manage cookies in WKWebView. This is needed in order to fix cookies not stored in iframes in WKWebView.

Please notice that this plugin requires you to use WKWebView.

Installation

This plugin isn't published in npm because it's private, so it must be installed via repo url:

cordova plugin add  https://github.com/moodlemobile/cordova-plugin-wkwebview-cookies

Methods

This plugin defines global WKWebViewCookies object.

Although in the global scope, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(WKWebViewCookies);
}
  • WKWebViewCookies.setCookie

WKWebViewCookies.setCookie

Stores a cookie in the WebView. If you only want to store a cookie to make cookies in iframe work then you can store any name/value, just make sure that the domain belongs to the iframe domain.

Supported Platforms

  • iOS 11+

Quick Example

WKWebViewCookies.setCookie({
    name: 'CookieName',
    value: 'CookieValue',
    domain: 'example.edu'
}).then(function() {
    // Success.
}).catch(function() {
    // Error.
});