Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get plugin to work #1

Closed
juliannehalversen opened this issue May 6, 2020 · 35 comments
Closed

Can't get plugin to work #1

juliannehalversen opened this issue May 6, 2020 · 35 comments

Comments

@juliannehalversen
Copy link

juliannehalversen commented May 6, 2020

This plugin does exactly what I need but I can't get it to work.
I added the plugin:
ionic cordova plugin add cordova-plugin-wkwebview-inject-cookie

Here is my package.json:

 "cordova": {
    "plugins": {
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-keychain-touch-id": {},
      "cordova-plugin-privacyscreen": {},
      "cordova-plugin-wkwebview-inject-cookie": {}
    },
    "platforms": [
      "ios",
      "android"
    ]
  }
}

Here is the plugin in my config.xml:
<plugin name="cordova-plugin-wkwebview-inject-cookie" spec="https://github.com/lucky3491/cordova-plugin-wkwebview-inject-cookie" />

And here is my app.component.ts where I try to inject a dummy cookie:

declare var wkWebView: any;

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {
  constructor(
    private platform: Platform,
    private splashScreen: SplashScreen,
    private statusBar: StatusBar,
    private authService: AuthenticationService,
    public router: Router,
    public loadingController: LoadingController,
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();

      if (this.platform.is('ios')) {
        const cookiesArray = [{
          domain: 'abc.xyz',
          name: 'cookie name',
          path: '/',
          value: 'cookie string'
        }, {} ];

        wkWebView.injectCookie(cookiesArray);
      }
   )}
  }
}

I have been working on this and am not sure where I'm going wrong. Any help would be greatly appreciated!

@kbrin423
Copy link

Hi! Same problem for me here :(

@juliannehalversen
Copy link
Author

juliannehalversen commented May 27, 2020

@kbrin423 I got mine to work. Below is the working code:

In my config.xml I added the inject cookie:

<plugin name="cordova-plugin-whitelist" spec="1.3.3" />
    <plugin name="cordova-plugin-statusbar" spec="2.4.2" />
    <plugin name="cordova-plugin-device" spec="2.0.2" />
    <plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
    <plugin name="cordova-plugin-ionic-webview" spec="^4.0.0" />
    <plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
    <plugin name="cordova-plugin-privacyscreen" spec="0.4.0" />
    <plugin name="cordova-plugin-wkwebview-inject-cookie" spec="1.1.4" />

In my package.json I have added it to my cordova plugins object:

"cordova": {
    "plugins": {
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-keychain-touch-id": {},
      "cordova-plugin-privacyscreen": {},
      "cordova-plugin-wkwebview-cookie-sync": {},
      "cordova-plugin-wkwebview-inject-cookie": {},
}

In my app.component.ts I declare wkWebView:

declare var wkWebView: any;

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['./app.component.scss'],
})

and then when the app is initializing I check if the platform is IOS. If it is then I will manually inject a cookie:

 initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();

      // This syncs the cookies on IOS devices when the app initializes.
      // This ensures that the login response cookie will be sent with all subsequent requests.
      if (this.platform.is('ios')) {
        wkWebView.injectCookie('YOUR API ENDPOINT HERE');
      }

This was a little tricky for me and there were any detailed instructions on how to set it up. Give this a try and let me know if you are still having issues.

@kbrin423
Copy link

I got mine to work too! thx 👍

@AlekseyPim
Copy link

@juliannehalversen What wkWebview plugin did you used?

@juliannehalversen
Copy link
Author

juliannehalversen commented Jun 18, 2020

@AlekseyPim As you can see in my config I used cordova-plugin-ionic-webview and for the cookie issue I used the one from this repo

@hiperiumlw
Copy link

@juliannehalversen I have an issue with my Ionic app that affects setting session cookies. When I do login in my app, my server API sends me an Header with "Set-Cookie" param. On Android, everything works fine...but...on iOs, I can't manage to save that cookie received from the Header Response. Could you please tell me if this method will work for me? Thanks in advance.

@lucky3491
Copy link
Owner

@juliannehalversen I have an issue with my Ionic app that affects setting session cookies. When I do login in my app, my server API sends me an Header with "Set-Cookie" param. On Android, everything works fine...but...on iOs, I can't manage to save that cookie received from the Header Response. Could you please tell me if this method will work for me? Thanks in advance.

@juliannehalversen you have to send cookies to different header param because that one is restricted to use

@hiperiumlw
Copy link

hiperiumlw commented Jun 26, 2020

@juliannehalversen I have an issue with my Ionic app that affects setting session cookies. When I do login in my app, my server API sends me an Header with "Set-Cookie" param. On Android, everything works fine...but...on iOs, I can't manage to save that cookie received from the Header Response. Could you please tell me if this method will work for me? Thanks in advance.

@juliannehalversen you have to send cookies to different header param because that one is restricted to use

@lucky3491
What do you mean exactly? I'm using Angular & Ionic, and when I make the Login request, i send the following
const headers = new HttpHeaders({ 'Content-Type': 'application/json' }); const options = ({ headers, withCredentials: true });

Like i said, on Android everything works fine, but on iOs, my cookie isn't set.
This plugin really can't help me with this?

Thanks.

@AlekseyPimenov
Copy link

@hiperiumlw Foe me the same problem with 'Set-Cookie', this plugin not help with that, it should fix another issue...
Also looking solution for 'Set-Cookie'

@lucky3491
Copy link
Owner

@hiperiumlw when you received cookies from your server. You have to send that cookies array to this plugin but from server normally you get cookies in set-cookies param that is restricted to use so you have to change your response header name for cookies

@hiperiumlw
Copy link

hiperiumlw commented Jun 26, 2020

@hiperiumlw when you received cookies from your server. You have to send that cookies array to this plugin but from server normally you get cookies in set-cookies param that is restricted to use so you have to change your response header name for cookies

@lucky3491 So, what you suggest is to receive another Cookie Response Header like "Cookie New Name" with the value and send it to the plugin? After that, all following requests will sent the Cookie Header Request Param?

@lucky3491
Copy link
Owner

@hiperiumlw Yes i am using this way and its working for me

@Carlosps
Copy link

Carlosps commented Jul 14, 2020

Thank you guys for your help.

Make sure when calling setCookie directly you add the '/', otherwise it won't work properly.

wkWebView.setCookie('url.com' + '/', 'cookieName', 'cookieValue');

setCookie expects (url, name, value, successCallback, errorCallback) as parameters.

@hiperiumlw
Copy link

Thank you guys for your help.

Make sure when calling setCookie you add the '/', otherwise it won't work properly.

wkWebView.setCookie(url + '/', 'cookieName', 'cookieValue');

But...Are you using the wkWebView.injectCookie('YOUR API ENDPOINT HERE'); ?

Why do you use wkWebView.setCookie instead of injectCookie?

@Carlosps
Copy link

Carlosps commented Jul 14, 2020

@hiperiumlw No, I am not using the injectCookie.

I was having some issues with injectCookie.

injectCookie: function (url, successCallback, errorCallback) { this.setCookie(url, "foo", "bar", successCallback, errorCallback); }

Why not use setCookie?

@hiperiumlw
Copy link

@hiperiumlw No, I am not using the injectCookie.
Why not use setCookie?

But....you are using this plugin, right?

@Carlosps
Copy link

Yes, as I said in my first comment.

@hiperiumlw
Copy link

hiperiumlw commented Jul 14, 2020

Yes, as I said in my first comment.

Is it working with the simulator or only with real devices...? Only asking :)

@Carlosps
Copy link

Carlosps commented Jul 14, 2020

Is it working with the simulator or only with real devices...? Only asking :)

I haven't tested with the simulator yet, only using the device.

@hiperiumlw
Copy link

Is it working with the simulator or only with real devices...? Only asking :)

I haven't tested with the simulator yet, only using the device.

And which versions of iOs have you tried? Thanks!

@Carlosps
Copy link

Carlosps commented Jul 14, 2020

And which versions of iOs have you tried? Thanks!

iOS software version: 13.5.1

@julitroalves
Copy link

@juliannehalversen thanks a lot for your clarification about how to use this plugin with ionic.
Another tip for all install plugin with link of this github plugin because there is another plugin with the same name, and when you run it the another plugin was installed.
Please run: cordova plugin add https://github.com/lucky3491/cordova-plugin-wkwebview-inject-cookie

@sachinkumaram-veoci
Copy link

sachinkumaram-veoci commented Oct 8, 2020

@hiperiumlw when you received cookies from your server. You have to send that cookies array to this plugin but from server normally you get cookies in set-cookies param that is restricted to use so you have to change your response header name for cookies

Is it working with iOS 14.0? mine is not working, how to debug it?

@hiperiumlw
Copy link

@hiperiumlw when you received cookies from your server. You have to send that cookies array to this plugin but from server normally you get cookies in set-cookies param that is restricted to use so you have to change your response header name for cookies

Is it working with iOS 14.0? mine is not working, how to debug it?

Have just tried with iOS 14 and it doesn't work...
Any news about iOS 14 versions? Anyone?

@juliannehalversen
Copy link
Author

@juliannehalversen thanks a lot for your clarification about how to use this plugin with ionic.
Another tip for all install plugin with link of this github plugin because there is another plugin with the same name, and when you run it the another plugin was installed.
Please run: cordova plugin add https://github.com/lucky3491/cordova-plugin-wkwebview-inject-cookie

Yes, thanks for clarifying. I had run into that issue as well which caused me tons of confusion

@razam217
Copy link

Its not working for me even on iOS 12.4.6, iPhone 5s :(

@lucky3491
Copy link
Owner

@hiperiumlw it is working for me in ios 14 not event change anything in this

@siphiwe
Copy link

siphiwe commented Nov 24, 2020

@kbrin423 I got mine to work. Below is the working code:

In my config.xml I added the inject cookie:

<plugin name="cordova-plugin-whitelist" spec="1.3.3" />
    <plugin name="cordova-plugin-statusbar" spec="2.4.2" />
    <plugin name="cordova-plugin-device" spec="2.0.2" />
    <plugin name="cordova-plugin-splashscreen" spec="5.0.2" />
    <plugin name="cordova-plugin-ionic-webview" spec="^4.0.0" />
    <plugin name="cordova-plugin-ionic-keyboard" spec="^2.0.5" />
    <plugin name="cordova-plugin-privacyscreen" spec="0.4.0" />
    <plugin name="cordova-plugin-wkwebview-inject-cookie" spec="1.1.4" />

In my package.json I have added it to my cordova plugins object:

"cordova": {
    "plugins": {
      "cordova-plugin-inappbrowser": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-keychain-touch-id": {},
      "cordova-plugin-privacyscreen": {},
      "cordova-plugin-wkwebview-cookie-sync": {},
      "cordova-plugin-wkwebview-inject-cookie": {},
}

In my app.component.ts I declare wkWebView:

declare var wkWebView: any;

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
  styleUrls: ['./app.component.scss'],
})

and then when the app is initializing I check if the platform is IOS. If it is then I will manually inject a cookie:

 initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();

      // This syncs the cookies on IOS devices when the app initializes.
      // This ensures that the login response cookie will be sent with all subsequent requests.
      if (this.platform.is('ios')) {
        wkWebView.injectCookie('YOUR API ENDPOINT HERE');
      }

This was a little tricky for me and there were any detailed instructions on how to set it up. Give this a try and let me know if you are still having issues.

Hi there,
Thanks for confirming that there's hope. I've done what you describe but not winning. Do you know what the variable wkWebView is referencing? Without instantiating anything, it calls an injectCookie() method. Not sure where to start debugging my issue, really. Any pointers would be appreciated. I'm using ionic 3.9.9 with cordova-ios 5.1.1. My webview is cordova-plugin-wkwebview-engine 1.2.1. The ionic webview couldn't even successfully make API calls, for some reason I couldn't fathom. Any assistance would be appreciated

@newuser44
Copy link

newuser44 commented Dec 3, 2020

Yeah I tried above (I had to run the add command to get the plugin installed).

My bad, I can't even get the plugin installed.

Failed to install 'cordova-plugin-wkwebview-inject-cookie': Error: Unable to load Platform API from /Users/w437982/work/WebKit/gf-efs-mobile-mobileapps/pay-control/platforms/ios/cordova/Api.js:
Cannot find module 'unorm'

@newuser44
Copy link

@hiperiumlw Foe me the same problem with 'Set-Cookie', this plugin not help with that, it should fix another issue...
Also looking solution for 'Set-Cookie'

Any fix?

@kbrin423
Copy link

kbrin423 commented Dec 8, 2020

Hi! Now i installed this plugin :https://github.com/oracle/cordova-plugin-wkwebview-file-xhr 💯

@newuser44
Copy link

Hi! Now i installed this plugin :https://github.com/oracle/cordova-plugin-wkwebview-file-xhr 💯

Thanks. How do you use this to do cookies?

@aronAtWex
Copy link

@hiperiumlw it is working for me in ios 14 not event change anything in this

How did you get this working for ios 14.
I had everything working with ios 13.5 pushed up for apple and they rejected it.
I'm trying in a emulator with ios 14 and it does not work.
Never got a clear answer/idea what to put in for the domain. Ionic/cordova apps have their own domain.
localhost was working fine with 13.5. Maybe path is more important.
Now I'm stuck. This plugin should be closed if it does not work with ios 14. Apple will reject it.

@luizchaves97
Copy link

@newuser44 Do you find how to use this plugin to get cookies?

@newuser44
Copy link

@newuser44 Do you find how to use this plugin to get cookies?

All the plugs I tried, including this one, I could never get working. Seems like a good number of them are not supported or have not been updated with the ios 14 updates.

What I did to get this working was.
Removing any plugs I had to fix cookies for WKWebView.

Storing cookies locally -- had to write some new code to use local storage instead of cookies. So far its working but I hear ios can pretty much clear memory whenever it wants to.

For login cookies in the config.xml I added a hostname tag under the ios section.

This solved the problem of CORS and cookies being stored because the ios app thinks it making the call from the same server. ios app is dev.test.com and I'm making my api calls to dev.test.com.

Does have to be exact. test.com won't work. (Unless that is the site).

I already had a webpack.config.js script to rewrite some values in config.xml depending on which environment I was building for. I hooked into that and other environment values to rewrite this Hostname line depending on the build.

So far things have worked great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests