how to block a specific cookie from a specific site

11,170

Achievement unlocked - Selective cookie clearing

By default, browsers don't allow such a fine-grained control over cookies: usually you can either block all third-party cookies or block all cookies for a given domain. Blocking everything is not an option because you'll easily end up breaking basic functionality (e.g. user login). In this case you have to resort to userscripts or extensions.


Firefox - userscript solution

This is the code I've come up with. Tested with Firefox 26.0, Greasemonkey 1.14.

// ==UserScript==
// @name        JSFiddlePanelReset
// @namespace   net.jsfiddle.userscripts
// @description Resets panels back to their default size whenever the site is loaded.
// @version     1.0
// @icon        http://jsfiddle.net/favicon.png
// @grant       none
// @include     http://jsfiddle.net/*
// @match       http://jsfiddle.net/*
// ==/UserScript==

(function (){

    // set the domain
    var domain = ".jsfiddle.net";

    // get a date in the past
    var expireDate = new Date(-1).toUTCString();

    // clear the size-related cookie and force it to expire
    document.cookie = "window_sizes=; domain=" + domain + "; path=/; expires=" + expireDate;

})();

Remarks

As pointed out by @Brock Adams in another question, there are major limitations on what Greasemonkey can delete:

  • The cookies you want to delete are on the current page's domain.
  • They are not "Secure cookies".
  • The cookie path (which cannot be detected by Greasemonkey) is the default path, /.
  • No cookies are set by javascript, after the page loads.
  • The thing tracking you really is a "cookie". Many websites use a variety of other techniques, including LSO's, local storage, etc.

References


Chromium-based browsers - extension

While the above userscript does clear the specified cookie, the JSFiddle panels are not reset for whatever reason. Since that's not the type of browser I use, I didn't invest too much time trying to understand why; maybe someone else can shed some light on this. As an alternative you can use the Edit This Cookie extension.

Edit This Cookie

Among other things, this particular extension can block specific cookies. You can filter them by domain, name, and value.

Blocked cookie

References

Share:
11,170

Related videos on Youtube

joeytje50
Author by

joeytje50

I am a Master student in Computer Science and hobbyist web developer, experienced in html css3 js regex and a beginner in svg php python c++. I like to think outside the box to find alternative uses for existing features, such as with my CSS3 mineturtle, or with this supposedly impossible question. I came up with CSS3 :checked-based tab menus independently in 2011 (back when IE8 was still by far the most used browser). A personal dislike of mine is jQuery UI's default styling being used so often without being customised. The visited item on your own userprofile that shows the dates you logged in, for example, just doesn't blend in with the other styles at all. </rant>

Updated on September 18, 2022

Comments

  • joeytje50
    joeytje50 over 1 year

    I have started getting quite active on StackOverflow recently, so I've been opening fairly many links to http://jsfiddle.net, but since I'd need to resize the panels regularly to see the specific code posted in the way the code was intended, I usually end up with some pretty weird configurations for the panels. Because I would prefer not having to resize the windows to a more normal setting every time, I would like to block the window_sizes cookie from jsfiddle, but when I tried googling for how to block a single cookie from a specific site, I could find nothing.

    I've also tried checking the settings for both Chrome and Firefox, but neither have the option to block a specific cookie, only to block certain domains.

    I'm mostly wondering on how to block this specific cookie in Chrome (which is my default browser), but I think it might also be useful for anybody else having the same problem to also include the methods for other browsers too, if that's possible.

    • joeytje50
      joeytje50 over 10 years
      @techie007 oh dear, that makes me get afraid this is not possible...
    • Ƭᴇcʜιᴇ007
      Ƭᴇcʜιᴇ007 over 10 years
      I agree, I'm not sure there's an answer to be had. :(
    • and31415
      and31415 over 10 years
      Would editing/deleting a specific cookie be a viable workaround?
    • joeytje50
      joeytje50 over 10 years
      @and31415 anything that would automatically prevent a certain cookie from being stored, accessed, or existing. If it's a small userscript, that's fine; if it's a built-in setting, that'd be great of course. I wouldn't like to have to manually delete the cookie every time I want to reset it though.
    • joeytje50
      joeytje50 over 10 years
      @and31415 could you post the code that worked for you? I am not really able to get it to work.
    • and31415
      and31415 over 10 years
      @joeytje50 Sure.