I have created a bookmarklet that tries to read and write with localStorage
with the following data:
url:
data:text/html;base64,PGRvY3R5cGUgaHRtbD4KPGh0bWw+Cjxib2R5Pgo8c2NyaXB0Pgpsb2NhbFN0b3JhZ2Uuc2V0SXRlbSgnY29udGVudCcsICdoZWxsbyB3b3JsZCcpOwpkb2N1bWVudC53cml0ZShsb2NhbFN0b3JhZ2UuZ2V0SXRlbSgnY29udGVudCcpKTsKPC9zY3JpcHQ+CjwvYm9keT4KPC9odG1sPg==
This translates to following code in the browser:
<doctype html>
<html>
<body>
<script>
localStorage.setItem('content', 'hello world');
document.write(localStorage.getItem('content'));
</script>
</body>
</html>
This code tries to write the string hello world
to the browser's localStorage, read the string and finally write it to the page.
However, this results in the following error:
Uncaught SecurityError: Failed to read the 'localStorage' property from 'Window': Storage is disabled inside 'data:' URLs.
As this approach doesn't work, it brings me to the question: How to save data to the browser with data:
URL? Is there some other API than localStorage
that I could use to save data in data:
URLs?
EDIT:
Cookies do not work. Trying to access cookies gives the following error:
Uncaught DOMException: Failed to read the 'cookie' property from 'Document': Cookies are disabled inside 'data:' URLs.
EDIT 2:
File system API does not work either. Fails with the error object:
A Data URL is a URI scheme that provides a way to inline data in an HTML document. or you can encode it in a special format, called Data URL, which makes it possible to embed the image directly in the HTML document, so the browser does not have to make a separate request to get it.
HTML web storage provides two objects for storing data on the client: window.localStorage - stores data with no expiration date. window.sessionStorage - stores data for one session (data is lost when the browser tab is closed)
Why not use 0x0 images to query a HTTPS origin that simply stores data in a query string to a cookie so you can retrieve it by loading a dynamic script file based on the cookie content? If that origin caches itself, it will run offline.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With