Skip to content

ikosta/cordova-plugin-cookies

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cordova-plugin-cookies

npm version MIT Licence

This plugin returns the cookies from the webview for a specific url so the cookies can be used e.g. to get the cookies from cordova-plugin-inappbrowser and pass it to cordova-plugin-advanced-http.

Installation

cordova plugin add cordova-plugin-cookies

Supported Platforms

  • Android
  • iOS

Limitations

It doen't work with the UIWebView on iOS (It's deprecated by Apple).

Usage

Plain

// get cookie string from webview
window.cordova.plugins.CookiesPlugin.getCookie(url, (cookies) => {
  // log cookies
  console.log(url, cookies);
});

Extended

// create in app browser
const iab = this.inAppBrowser.create(url, "_blank");

// check for cookies on every loadstop
iab.on("loadstop").subscribe(() => {
  // get cookie string from webview
  (window as any).cordova.plugins.CookiesPlugin.getCookie(
    url,
    async (cookies: string) => {
      // set cookies to http plugin
      cookies.split(";").forEach((cookie) => {
        this.http.setCookie(url, cookie);
      });

      // check if connected
      if (await this.isUserAuthenticated()) {
        iab.close();
      }
    }
  );
});

About

Cordova Cookies Plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published