In JavaScript, the Document afterscriptexecute event once fired when a static<script> finished executing (MDN). It does not fire for scripts added dynamically (for example with appendChild()).
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for afterscriptexecute. Start with this line.
JavaScript
addEventListener("afterscriptexecute", fn)
Call
What it does
addEventListener("afterscriptexecute", fn)
Primary signature.
Built into the browser. Listen with document.addEventListener("afterscriptexecute", …) — no import required.
Library declarations
JavaScript
addEventListener("afterscriptexecute", fn)
Parameters
Parameter
Description
Static <script>
Required. Dynamic scripts were skipped (MDN)
Modern path
Required. script load / error
Return Value
Return Value
Description
*
Fires as a Document event (listener receives the Event object).
JavaScript Examples
Example 1 — addEventListener("afterscriptexecute")
MDN style: listen on document and read the finished script’s id (legacy Firefox only).
JavaScript
function finished(e) {
console.log(`Finished script with ID: ${e.target.id}`);
}
document.addEventListener("afterscriptexecute", finished);
console.log("Listener attached (may never fire today)");
Prefer load/error over afterscriptexecute
after append, __demoRan: true
How It Works
Create a script node. Inline text runs as soon as you append it.
Append to the document. The browser executes the script immediately.
Confirm the side effect.window.__demoRan becomes true.
For external files. Set src and listen for load / error — the cross-browser replacement.
Compatibility
Browser Support
afterscriptexecute is a Deprecated and Non-standard Gecko Document event (MDN). Other engines never implemented it; modern Firefox no longer dispatches it to web content.
✓ Deprecated · Non-standard
Document afterscriptexecute
Legacy Firefox-only static-script finish event — do not build features on it.
LegacyNot for new apps
Google ChromeNever implemented
Unavailable
Mozilla FirefoxLegacy only · removed / disabled in modern versions
Avoid
Apple SafariNever implemented
Unavailable
Microsoft EdgeNever implemented (Chromium)
Unavailable
OperaNever implemented (Chromium)
Unavailable
Internet ExplorerNo afterscriptexecute support
Unavailable
afterscriptexecuteDeprecated
Bottom line: Recognize it in old Gecko code, then migrate. Prefer script load/error events or ES modules. Remember: even historically, dynamically appended scripts did not fire this event.
Frequently Asked Questions
A proprietary Gecko (Firefox) Document event that fired after a static <script> finished executing. MDN marks it Deprecated and Non-standard. It was never a finished web standard.
No. MDN: it does not fire when a script element is added dynamically (for example with appendChild()). It only applied to static scripts in the markup in supporting legacy Firefox.
No. Prefer portable APIs such as the script element’s load and error events, ES modules, or MutationObserver when you need to watch scripts being inserted.
Historically only Firefox (Gecko). Chrome, Safari, and Edge never shipped it. Modern Firefox stopped dispatching it to web content.
In supporting legacy Firefox: document.addEventListener("afterscriptexecute", handler) or document.onafterscriptexecute = handler. Always feature-detect; do not assume the event exists.
A generic Event. There is no special payload beyond a normal Event object. Related learning: Document.currentScript and the sibling beforescriptexecute event.