Skip to content

Instantly share code, notes, and snippets.

@James-E-A
Last active July 30, 2025 19:58
Show Gist options
  • Save James-E-A/ed7e346bf57011a55b07bbe782dc5271 to your computer and use it in GitHub Desktop.
Save James-E-A/ed7e346bf57011a55b07bbe782dc5271 to your computer and use it in GitHub Desktop.
Javascript currentScript in async script
<script>(async (currentScript) => { // scoped to this IIFE, does not pollute global namespace or vanish on future event loop ticks
// You are 100% free to do async stuff in this block
await new Promise(window.requestAnimationFrame);
window.alert(currentScript);
// ... //
})(document.currentScript).then((value) => {if (value !== undefined) console.debug(value);}, (error) => {console.error(error); debugger;});</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment