Closed wjtk4444 closed 4 years ago
There's no API to modify localStorage explicitly from Add-ons, so that can't be done. I could provide a way to call tabs.executeScript
which then could call localStorage APIs - but this feels like bloat when user script managers like Grease/Tamper/Violentmonkey exist?
Cookie editor sucks a bit, it could use a revamp
I'd agree. PRs welcome.
Fair enough, for some reason I assumed that onBeforeRequest
allows for that. Should've checked before opening this issue, sorry for that.
--
In case someone else will find this thread in the future:
user script managers like Grease/Tamper/Violentmonkey exist
Apparently, neither GM_setValue nor GM.setValue seems to work in 2020, I had to resort to using this one instead:
window.localStorage.setItem('key', 'value');
The solution is not perfect because technically the page can try accessing those before the script is exectuted, but setting the Run-At
option to document-start
in Violentmonkey did the job for me.
Violentmonkey did the job for me
Glad that works for you. I'm curious, is there a way to restrict the script to certain containers?
I don't think so. Just skimmed trough Violentmonkey's options and documentation, didn't find anything that mentions containers. If other extensions can see what containers are being used (and I assume they can, duh), then it can be implemented. Probably. I'm not very familiar with browser extensions.
Right, I've checked the user scripts Add-ons as well, and none seems to support executing scripts only in certain containers. Added an rudimentary "Scripts" section to the advanced TC preferences in v1.8beta1. That lets you execute scripts only in TCs. To set localStorage something like
window.wrappedJSObject.localStorage.setItem('foo', 'bar');
should work - feedback very welcome.
(wrappedJSObject
is needed because of Xray vision)
(the debug log logs things if the script fails to execute)
It seems to work, but the question "why?" arises. I use TC for every single tab, so for me it's the same as Violentmoney. While I appreciate your efforts, I don't think this is going in the right direction. Maybe linking scripts to permament containers would be a desired feature, but I don't think that TC covers those.
My intention when opening this issue was to (ab?)use onBeforeRequest
some more, mainly to persist certain page settings (theme, layout, language, etc.) and have the rest nuked when closing the tab.
It seems to work
Thanks for testing.
but the question "why?" arises
The same answer as for the "Cookies" applies: you might want to modify local storage for sites that otherwise should've a clean storage.
Maybe linking scripts to permament containers would be a desired feature, but I don't think that TC covers those.
Correct, permanent containers would be out of scope.
My intention when opening this issue was to (ab?)use onBeforeRequest some more, mainly to persist certain page settings (theme, layout, language, etc.) and have the rest nuked when closing the tab.
That's exactly what the "Scripts" feature provides (just not by using onBeforeRequest
/ onBeforeSendHeaders
but executeScript
instead). But if you're happy with an actual user scripts manager that's fine. :)
I have actually an use-case for this and so I implemented it since it was almost no effort. (user scripts manager doesn't help in my case since the storage must be different for permanent containers; and since those are permanent anyway, I don't need an user scripts manager at all, since configuring the sites once is enough)
That being said,
I don't think this is going in the right direction
if you have actual concerns why the feature should not land in stable TC, please let me know.
Cookie editor sucks a bit, it could use a revamp
Added a way to edit cookies (and scripts) in v1.8beta2 - hope that helps.
After cookies being fixed to work with fpi, for a few months I considered TC to be feature-complete software. But today I come with another (un?)reasonable request. Would it be possible to add a local storage editor for containers?
PS. Cookie editor sucks a bit, it could use a revamp. Definitely not high priority though, one can just export settings in json, edit cookies and import it back.