Created
December 25, 2025 16:27
-
-
Save ulrischa/c4c4b18065cafc17def687eb7a91a6ea to your computer and use it in GitHub Desktop.
Bookmarklet to show localStorage and sessionStorage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(()=>{try{const dump_storage=(name)=>{const result={name,ok:false,error:null,items:{}};let s=null;try{s=window[name];}catch(e){result.error=`Accessing window.${name} threw: ${String(e)}`;return result;}if(!s){result.error=`window.${name} is not available`;return result;}let len=0;try{len=s.length;}catch(e){result.error=`${name}.length threw: ${String(e)}`;return result;}const keys=[];for(let i=0;i<len;i++){try{keys.push(s.key(i));}catch(e){keys.push(null);result.error=(result.error?result.error+"\n":"")+`${name}.key(${i}) threw: ${String(e)}`;}}for(const k of keys){if(k===null)continue;try{result.items[k]=s.getItem(k);}catch(e){result.items[k]=null;result.error=(result.error?result.error+"\n":"")+`${name}.getItem(${JSON.stringify(k)}) threw: ${String(e)}`;}}result.ok=result.error===null;return result;};const payload={origin:location.origin,href:location.href,timestamp:new Date().toISOString(),localStorage:dump_storage("localStorage"),sessionStorage:dump_storage("sessionStorage")};const text=JSON.stringify(payload,null,2);const existing=document.getElementById("__storage_dump_overlay__");if(existing)existing.remove();const overlay=document.createElement("div");overlay.id="__storage_dump_overlay__";overlay.style.cssText="position:fixed;inset:0;z-index:2147483647;background:rgba(0,0,0,.72);padding:12px;display:grid;grid-template-rows:auto 1fr;gap:10px;";const panel=document.createElement("div");panel.style.cssText="background:#fff;color:#111;border-radius:12px;overflow:hidden;display:grid;grid-template-rows:auto 1fr;max-width:1100px;margin:0 auto;width:100%;box-shadow:0 10px 40px rgba(0,0,0,.35);";const bar=document.createElement("div");bar.style.cssText="display:flex;gap:8px;align-items:center;justify-content:space-between;padding:10px 12px;border-bottom:1px solid #e5e5e5;font:14px/1.3 system-ui,-apple-system,Segoe UI,Roboto,Arial;";const left=document.createElement("div");left.textContent=`Storage Dump: ${location.origin}`;left.style.cssText="font-weight:600;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;max-width:70vw;";const btns=document.createElement("div");btns.style.cssText="display:flex;gap:8px;align-items:center;";const mk_btn=(label)=>{const b=document.createElement("button");b.type="button";b.textContent=label;b.style.cssText="appearance:none;border:1px solid #ddd;background:#f7f7f7;border-radius:10px;padding:8px 10px;font:14px system-ui,-apple-system,Segoe UI,Roboto,Arial;";return b;};const btn_copy=mk_btn("Copy");const btn_download=mk_btn("Download");const btn_close=mk_btn("Close");btn_close.style.cssText+="background:#ffecec;border-color:#ffb3b3;";bar.appendChild(left);btns.appendChild(btn_copy);btns.appendChild(btn_download);btns.appendChild(btn_close);bar.appendChild(btns);const area=document.createElement("textarea");area.value=text;area.readOnly=true;area.spellcheck=false;area.style.cssText="width:100%;height:100%;border:0;outline:0;padding:12px;font:12px/1.4 ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;resize:none;";const body=document.createElement("div");body.style.cssText="height:70vh;";body.appendChild(area);panel.appendChild(bar);panel.appendChild(body);overlay.appendChild(panel);document.documentElement.appendChild(overlay);const copy_fallback=()=>{area.focus();area.select();try{document.execCommand('copy');}catch(_){};area.setSelectionRange(0,0);};btn_copy.onclick=async()=>{try{if(navigator.clipboard&&navigator.clipboard.writeText){await navigator.clipboard.writeText(area.value);}else{copy_fallback();}}catch(_){copy_fallback();}};btn_download.onclick=()=>{try{const blob=new Blob([area.value],{type:"application/json"});const a=document.createElement("a");a.href=URL.createObjectURL(blob);a.download=("storage-dump-"+location.host+"-"+Date.now()+".json").replace(/[^a-z0-9._-]/gi,"_");a.click();setTimeout(()=>URL.revokeObjectURL(a.href),2000);}catch(e){alert("Download failed: "+String(e));}};btn_close.onclick=()=>overlay.remove();overlay.addEventListener("click",(e)=>{if(e.target===overlay)overlay.remove();});}catch(e){alert("Bookmarklet error: "+String(e));}})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment