Various articles and SO answers suggest that deleting cookie via JS should be done like this:
document.cookie = cookieName + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
or if we need to specify domain/path, like this:
document.cookie = cookieName + "=" +
(path ? `;path=${path}` : "") +
(domain ? `;domain=${domain}` : "") +
";expires=Thu, 01 Jan 1970 00:00:01 GMT";
Now, in a non-root location (like https://classic.tiddlywiki.com/upgrade/) a more complicated situation takes place. If you open it and type document.cookie
in console, you'll get one value (with no domain
, path
or expires
specified):
TiddlyWikiClassicOptions=chkRegExpSearch:%22false%22 chkCaseSensitiveSearch:%22false%22 chkIncrementalSearch:%22true%22 chkAnimate:%22true%22 chkSaveBackups:%22true%22 chkAutoSave:%22false%22 chkGenerateAnRssFeed:%22false%22 chkSaveEmptyTemplate:%22false%22 chkOpenInNewWindow:%22true%22 chkToggleLinks:%22false%22 chkHttpReadOnly:%22true%22 chkForceMinorUpdate:%22false%22 chkConfirmDelete:%22true%22 chkInsertTabs:%22false%22 chkUsePreForStorage:%22true%22 chkDisplayInstrumentation:%22false%22 chkRemoveExtraMarkers:%22false%22 txtBackupFolder:%22%22 txtEditorFocus:%22text%22 txtMainTab:%22Timeline%22 txtMoreTab:%22moreTabAll%22 txtMaxEditRows:%2230%22 txtFileSystemCharSet:%22UTF-8%22 txtTheme:%22%22 txtUserName:%22YourName%22
and writing in console
document.cookie = 'TiddlyWikiClassicOptions=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
doesn't remove the cookie (or change its value) (document.cookie
gives the same). Moreover, writing
document.cookie = 'TiddlyWikiClassicOptions=lalala';
doesn't change the existing cookie, but rather addes another one with the same name:
TiddlyWikiClassicOptions=lalala; TiddlyWikiClassicOptions=chkRegExpSearch:%22false%22 chkCaseSensitiveSearch:%22false%22 chkIncrementalSearch:%22true%22 chkAnimate:%22true%22 chkSaveBackups:%22true%22 chkAutoSave:%22false%22 chkGenerateAnRssFeed:%22false%22 chkSaveEmptyTemplate:%22false%22 chkOpenInNewWindow:%22true%22 chkToggleLinks:%22false%22 chkHttpReadOnly:%22true%22 chkForceMinorUpdate:%22false%22 chkConfirmDelete:%22true%22 chkInsertTabs:%22false%22 chkUsePreForStorage:%22true%22 chkDisplayInstrumentation:%22false%22 chkRemoveExtraMarkers:%22false%22 txtBackupFolder:%22%22 txtEditorFocus:%22text%22 txtMainTab:%22Timeline%22 txtMoreTab:%22moreTabAll%22 txtMaxEditRows:%2230%22 txtFileSystemCharSet:%22UTF-8%22 txtTheme:%22%22 txtUserName:%22YourName%22
That's what I get in clean Chrome. I've also tried that in Vivaldi with installed HTML5 Storage Manager All in One (Chrome extension) and it shows the same, except for the case when 2 cookies are present: while console gives the same line as above (on document.cookie
), the extension shows
This doesn't happen at https://classic.tiddlywiki.com/ (deleting/editing works as expected).
Now, I figured that to delete the initial cookie, I had to do
document.cookie = 'TiddlyWikiClassicOptions=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
and if I added the lalala
one, I also had to do
document.cookie = 'TiddlyWikiClassicOptions=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
to remove the second one.
I wonder, how can I determine which path should I use? document.cookie
seems to be silent about the "scope" of each cookie. Or is this something introduced by design and I always have to know which cookie was assigned for which path?
PS I've seen a post which makes me think that there's the same problem about domains (it's in Russian), so I wonder how to get the domain assosiated with the cookie as well.