Re: [ServiceWorker] Add cookie accessor/setter methods? (#707)

Also, perhaps self.cookies.match and self.cookies.matchAll might make more sense since it's an asynchronous operation rather than a simple getter. I think the name should be optional in each case.

self.cookies.match().then(function(cookie){ /* gets the first cookie, if any are visible to scripts on this origin (one of the narrowest-scoped ones) */ })
self.cookies.matchAll().then(function(cookies) { /* gets all cookies visible to scripts on this origin, ordered from narrowest-scoped to broadest-scoped */ })
self.cookies.match('SAPISID').then(function(cookie){ /* gets the narrowest-scoped cookie named 'SAPISID' visible to scripts on this origin, if at least one exists */ })
self.cookies.matchAll('SAPISID').then(function(cookies){ /* gets all cookies named 'SAPISID' visible to scripts on this origin, ordered from narrowest-scoped to broadest-scoped */ }

This lookup interface provides the same capabilities as document.cookie. If more capabilities are declared fit for web consumption they might be implemented by adding a second optional parameter with matching options.

Would you expose parameters on read cookies? The document.cookie interface does not, and simply concatenates all the in-scope cookies in a fairly well-defined but not standardized order.

---
Reply to this email directly or view it on GitHub:
https://github.com/slightlyoff/ServiceWorker/issues/707#issuecomment-110445154

Received on Tuesday, 9 June 2015 17:51:34 UTC