Skip to content

Instantly share code, notes, and snippets.

@mrrootsec
Last active October 24, 2025 04:45
Show Gist options
  • Select an option

  • Save mrrootsec/0a71df24f361677ffa6e2e41d3f2e971 to your computer and use it in GitHub Desktop.

Select an option

Save mrrootsec/0a71df24f361677ffa6e2e41d3f2e971 to your computer and use it in GitHub Desktop.
Convert fetch to Burp RAW Request
javascript:(function(){const c='burp_converter_'+Date.now(),d=document.createElement('div');d.id=c;d.innerHTML='<div style="position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);width:90%;max-width:800px;max-height:90vh;background:#f5f5f5;border:2px solid #333;border-radius:8px;box-shadow:0 4px 20px rgba(0,0,0,0.3);z-index:999999;font-family:\'Courier New\',monospace;overflow:hidden;display:flex;flex-direction:column"><div style="background:#222;color:#fff;padding:12px 16px;font-weight:bold;font-size:14px;display:flex;justify-content:space-between;align-items:center"><span>Fetch to Burp Converter</span><button id="'+c+'_close" style="background:#ff4444;color:white;border:none;padding:4px 8px;border-radius:3px;cursor:pointer;font-weight:bold">×</button></div><div style="flex:1;overflow-y:auto;padding:16px;display:flex;flex-direction:column;gap:16px"><div><label style="display:block;margin-bottom:6px;font-weight:bold;font-size:12px">Input (fetch call, object, or raw HTTP):</label><textarea id="'+c+'_input" style="width:100%;height:150px;padding:8px;border:1px solid #ccc;border-radius:4px;font-family:\'Courier New\',monospace;font-size:12px;box-sizing:border-box;resize:vertical" placeholder="Paste fetch() call, JSON object, or raw HTTP request..."></textarea></div><div style="display:flex;gap:8px"><button id="'+c+'_convert" style="flex:1;padding:10px 16px;background:#007bff;color:white;border:none;border-radius:4px;font-weight:bold;cursor:pointer;font-size:13px">Convert to Burp</button><button id="'+c+'_clear" style="padding:10px 16px;background:#6c757d;color:white;border:none;border-radius:4px;font-weight:bold;cursor:pointer;font-size:13px">Clear</button></div><div><label style="display:block;margin-bottom:6px;font-weight:bold;font-size:12px">Burp HTTP Request:</label><textarea id="'+c+'_output" style="width:100%;height:150px;padding:8px;border:1px solid #ccc;border-radius:4px;font-family:\'Courier New\',monospace;font-size:12px;box-sizing:border-box;resize:vertical;background:#fff;color:#333" readonly placeholder="Converted request will appear here..."></textarea></div><div id="'+c+'_error" style="display:none;padding:10px;background:#f8d7da;border:1px solid #f5c6cb;border-radius:4px;color:#721c24;font-size:12px"></div><button id="'+c+'_copy" style="width:100%;padding:12px 16px;background:#28a745;color:white;border:none;border-radius:4px;font-weight:bold;cursor:pointer;font-size:13px;display:none">Copy & Close</button></div></div>';document.body.appendChild(d);const e=document.getElementById(c+'_input'),f=document.getElementById(c+'_output'),g=document.getElementById(c+'_error'),h=document.getElementById(c+'_convert'),i=document.getElementById(c+'_clear'),j=document.getElementById(c+'_copy'),k=document.getElementById(c+'_close');function l(m){g.textContent=m;g.style.display='block'}function n(){g.style.display='none';g.textContent=''}function o(p){try{return JSON.parse(p)}catch(q){return null}}function r(s){s=s.trim();if(/^(GET|POST|PUT|DELETE|PATCH|HEAD|OPTIONS|TRACE|CONNECT)\s+/i.test(s))return{type:'raw',content:s};const t=s.match(/fetch\s*\(\s*['"`](.*?)['"`]\s*,\s*(\{[\s\S]*\})\s*\)/i);if(t){const u=t[1],v=t[2];let w=o(v);if(!w&&(w=x(v),!w))throw new Error('Failed to parse fetch options. Ensure headers and body are valid JSON.');return{type:'fetch',url:u,opts:w}}const y=o(s);if(y&&y.url)return{type:'object',url:y.url,opts:y};throw new Error('Input must be a fetch() call, object with "url" property, or raw HTTP request')}function x(z){const aa={};const ba=z.match(/"url"\s*:\s*"([^"]+)"/);if(ba)aa.url=ba[1];const ca=z.match(/"method"\s*:\s*"([^"]+)"/);if(ca)aa.method=ca[1];const da=z.match(/"headers"\s*:\s*(\{[^}]*\})/);if(da)aa.headers=ea(da[1]);const fa=z.match(/"body"\s*:\s*"([^"\\]*(\\.[^"\\]*)*)"/);if(fa){aa.body=fa[1];aa.body=aa.body.replace(/\\"/g,'"').replace(/\\\\/g,'\\').replace(/\\n/g,'\n')}return Object.keys(aa).length>0?aa:null}function ea(ga){const ha={};const ia=ga.matchAll(/"([^"]+)"\s*:\s*"([^"\\]*(\\.[^"\\]*)*)"/g);for(const ja of ia){let ka=ja[1];let la=ja[2];la=la.replace(/\\"/g,'"').replace(/\\\\/g,'\\').replace(/\\n/g,'\n');ha[ka]=la}return ha}function ma(na){if('raw'===na.type)return na.content;const oa=new URL(na.url),pa=na.opts.method||'GET',qa=na.opts.headers||{};let ra=na.opts.body||'';let sa=pa+' '+(oa.pathname+oa.search||'/')+' HTTP/1.1\r\n';let ta=oa.hostname;if(oa.port){const ua={'http:':'80','https:':'443'};oa.port!==ua[oa.protocol]&&(ta+=':'+oa.port)}sa+='Host: '+ta+'\r\n';const va=new Set(['host']),wa={};for(const xa in qa){const ya=xa.toLowerCase();'host'!==ya&&(wa[ya]={key:xa,value:qa[xa]},va.add(ya))}if(ra&&!va.has('content-length')){const za='string'==typeof ra?ra:JSON.stringify(ra);sa+='Content-Length: '+new TextEncoder().encode(za).length+'\r\n'}for(const aaa in wa)sa+=wa[aaa].key+': '+wa[aaa].value+'\r\n';sa+='\r\n';if(ra)sa+='string'==typeof ra?ra:JSON.stringify(ra);return sa}h.addEventListener('click',function(){n();const baa=e.value.trim();if(!baa){l('Please enter a fetch() call, object, or raw HTTP request.');return}try{const caa=r(baa),daa=ma(caa);f.value=daa;j.style.display='block'}catch(eaa){l(eaa.message);f.value='';j.style.display='none'}});i.addEventListener('click',function(){e.value='';f.value='';n();j.style.display='none'});j.addEventListener('click',async function(){const faa=f.value;try{if(navigator.clipboard&&navigator.clipboard.writeText)await navigator.clipboard.writeText(faa);else{const gaa=document.createElement('textarea');gaa.value=faa;document.body.appendChild(gaa);gaa.select();document.execCommand('copy');document.body.removeChild(gaa)}const haa=j.textContent;j.textContent='✓ Copied!';setTimeout(function(){j.textContent=haa;document.body.removeChild(d)},800)}catch(iaa){l('Failed to copy: '+iaa.message)}});k.addEventListener('click',function(){document.body.removeChild(d)});e.focus()})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment