Welcome guest, is this your first visit? Create Account now to join.
Page 1 of 2 12 LastLast
Results 1 to 10 of 14

This is a discussion on Proof of Concept: Saving extenion's options via cookie within the Plugins Development section, part of the Chrome Plugins category: I noticed everyone seemed to be using the bookmark API to save user data. Why not just use a cookie? ...


  1. #1
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default Proof of Concept: Saving extenion's options via cookie

    I noticed everyone seemed to be using the bookmark API to save user data. Why not just use a cookie?
    So I wrote this:
    http://logicplace.com/pc/projects/ch...ns%20Saver.crx

    If you don't have a cookie he will look like :| then you can click him to change between and

    I was going to add a js script to run an alert on google.com if the guy was smiling, but I can't figure out the events api. Can anyone help with that?

  2. #2
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    I know we can use cookies but.. cookies are temporary, are restricted a certain domain and can only store key:values.

    I sincerely thought about having CNT store local info in cookies.. but that would only work for some time. Meanwhile, I decided to simply wait for HTML5 stuff. It should be coming pretty soon.

    I could help with the events API.. what are you trying to do exactly ?
    If I understand your question correctly, all you need to do is :
    Create a contentscript that injects on http://www.google.com/* matches.
    You can then get the cookie via javascript, inside the content script.
    From there, send alert("whatever"); or if you need to use Chrome API :
    Create a toolstrip or a background page,
    Send a message from the content script to the toolstrip/background page which will then use the API you need.

    For an example, see http://code.google.com/p/customnewta...wse/#svn/trunk
    I inject CustomNewTab.js inside newtab pages, connect to the background page/toolstrip, wait for it to load the config and send the config json object and then modify the page accordingly.

    If you have any questions, feel free to ask
    Last edited by Kyrax; 06-16-2009 at 12:38 AM. Reason: Edited for clarity

  3. #3
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    Well the cookie is only accessible to the toolstrip, but I wanted the data in the content script so it can alert. I will check out your code in a bit but I'm just about to leave so I can't right now.

    However the fact that they're "restricted by a certain domain" is inapplicable with this example, more or less, because it's the toolstrip's cookie, the toolstrip will always retrieve that cookie no matter where website your browser/tab is pointed.

    However about it being temporary..I suppose it could be deleted at the user's request, but I set the cookie to expire in a leap year (and it resets it on start-up) so it's not likely to expire.

  4. #4
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    My main concern about Cookie's lifetime is that a lot of users set their browsers to delete cookies often (for example when they close it or every day/week...)

    EDIT: Now that I'm reading your post again.. I think I understand what you meant. Cookies set by toolstrips can be accessed from anywhere, as long as it's a request coming from the toolstrip. I highly doubt that toolstrips can read any cookie.. and that makes sense.

  5. #5
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    I just figured something out. Cookies saved by extensions (only really looked at toolstrips, mind you) are somehow saved outside of the scope of the rest of your cookies. Clearing cookies DOES NOT clear your extensions' cookie data. Thereby making this a completely legitimate save feature.
    Last edited by Waha; 06-17-2009 at 08:16 AM.

  6. #6
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    Wow, that sounds very interesting !..
    I wonder why they did that ?
    I hope it's not something that they plan to "fix".

  7. #7
    Luc VN's Avatar
    Luc VN is offline Senior Member
    Join Date
    Sep 2008
    Location
    Belgium - Europe
    Posts
    758

    Default

    I was just going to post a warning for CCleaner users...

    Thanks for the clarification Waha!

  8. #8
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    I'm looking for the download history file cause I can't figure out how to view a certain date on the download page, and stumbled upon "User Data\Default\Extension Cookies"
    So it seems this is intended functionality for saving.
    Also, not really inspecting the file extensively, it looks like it saves the cookie data only by extension ID, so your background page and toolstrip probably share the same cookie.
    I might test it out later.

    EDIT: Grabbed this and confirmed that's the case. Also deleted some entries from when extensions had the old ID format.
    Last edited by Waha; 07-02-2009 at 06:41 AM.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  9. #9
    OpenNingia is offline Senior Member
    Join Date
    Jul 2009
    Posts
    123

    Default

    I'm using bookmarks to store settings, is there any advantage in using cookies instead?

  10. #10
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    Bookmarks were absolutely not designed to save user preferences or settings.
    Cookies are used that way in a lot of web applications since they often represent the only way a web app can store something on the user's computer. HTML 5's local storage database is a solution to this problem.

    Also, by using bookmarks, you force a user to have bookmarks he might not want. Even if you save them under 'other bookmarks' some users don't even want that folder in the first place.

Page 1 of 2 12 LastLast

Similar Threads

  1. Chrome Plugins concept logo
    By Stamga in forum General Chat
    Replies: 13
    Last Post: 06-07-2009, 01:25 PM
  2. Saving zoom?
    By EV88 in forum Chrome Tips & Tricks
    Replies: 1
    Last Post: 03-13-2009, 10:00 PM
  3. Opening up some media; saving others
    By prr in forum Chrome Troubleshooting
    Replies: 0
    Last Post: 02-02-2009, 05:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •