cookies icon indicating copy to clipboard operation
cookies copied to clipboard

clearAll should use promise resolution in all cases

Open plaa opened this issue 3 years ago • 3 comments

The documentation indicates that clearAll returns a promise that is always fulfilled with a boolean on whether the cookies were successfully cleared or not. (This is not explicitly stated, but that's what you gather from CookieManager.clearAll().then((success) => ... with no catch clause.)

In reality, what is returned is:

iOS with useWebKit=false

  • Always resolves true

iOS with useWebKit=true

  • If on iOS 11.0 or greater: resolves true
  • On older iOS version: rejects

Android:

Thus, the promise may be resolved of rejected, and in no case does the resolved boolean indicate whether it was successful or not – the only case in which it resolves to false is to indicate that there were no cookies present in the first place.

plaa avatar Mar 30 '21 10:03 plaa

Nice catch, which behavior should be the accepted one?

safaiyeh avatar Apr 01 '21 01:04 safaiyeh

Personally I was confused with the success boolean, and in what case the operation could be unsuccessful and what to do then. (That's why I started digging into the code in the first place.) I also can't think of any use case for needing to know whether there were cookies that were cleared or not.

If designing it from scratch, I would probably return a promise that is fulfilled with no value, or rejected on iOS <11. This of course would be a breaking change.

Whatever the design, the most important thing is to have the cases clearly documented. The iOS version limitation is especially important. After noticing it I increased my iOS version requirement to 11 because in my use case it's unacceptable for the cookies not to be cleared.

plaa avatar Apr 01 '21 05:04 plaa

@plaa thanks for the feedback, I agree with the promise resolution should be consistent in all cases. I'll make a note for this issue to address that

safaiyeh avatar Apr 01 '21 15:04 safaiyeh