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 you support the GM_cookie API? #16

Open
cloudswave opened this issue Nov 11, 2023 · 3 comments
Open

Can you support the GM_cookie API? #16

cloudswave opened this issue Nov 11, 2023 · 3 comments

Comments

@cloudswave
Copy link

The API document GM_cookie

@cloudswave cloudswave changed the title Can you support the GM_cookie API Can you support the GM_cookie API? Nov 11, 2023
@warren-bank
Copy link
Owner

I probably won't be able to start working on it for a few days, but from a technical standpoint.. it seems doable. I'll let you know when I have a version available.

@warren-bank
Copy link
Owner

warren-bank commented Nov 26, 2023

quick update..

  • branch v04 is where all work on cookies begins
  • it corresponds with release versions: 4.x.x
    • 4.0.0
      • was the first release from this branch
      • it doesn't URL encode cookie values when set, but does URL decode cookie values when listed
    • 4.0.1
      • it does URL encode cookie values when set, and does URL decode cookie values when listed

I've been struggling with how encoding/decoding should be handled:

  1. transparently
    • which could potentially mess up the value
  2. manually
    • which could potentially include reserved characters and be truncated

I think I'll release (shortly) another version, which:

  • removes encoding/decoding from Java
  • adds encoding/decoding to the Javascript API, as a new optional details attribute
    • the API method signatures will be unchanged:
      • GM_cookie.set(details, callback)
        • if details.encode is truthy:
            details.value = encodeURIComponent(details.value)
      • GM_cookie.list(details, callback)
        • if details.decode is truthy:
            for (cookie of cookies) cookie.value = decodeURIComponent(cookie.value)
    • the default encoding/decoding methodology is: manually
      • input and output cookie values are verbatim

one technical note:

  • @grant GM_cookie is required to use this new feature

@warren-bank
Copy link
Owner

warren-bank commented Nov 26, 2023

update..

4.0.2 does exactly what I previously described..
which seems like the best compromise


btw, there are 2 relevant test userscripts.. that I used to validate behavior:

  1. GM_cookie.*
    • methods accept a callback parameter
  2. GM.cookie.*
    • methods return a Promise

PPS: they use console.log statements..

  • which, to see, you would need:
    • your laptop connected to your phone by adb
    • Chrome on your laptop, open to: chrome://inspect/#devices
  • it would probably be simpler to:
    var callback = function(cookies) {
      cookies = JSON.stringify(cookies, null, 2)
    
      unsafeWindow.confirm(cookies)
    
      unsafeWindow.document.body.appendChild(
        unsafeWindow.document.createTextNode(cookies)
      )
    }

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

2 participants