JavaScript Element afterscriptexecute Event

Beginner
5 min read
Updated: Nov 2026
3 examples
Event

Definition

In JavaScript, the Element afterscriptexecute event is a proprietary Gecko (Firefox) event fired after a script has been executed (MDN). It is not cancelable.

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)
CallWhat it does
addEventListener("afterscriptexecute", fn)Primary signature.

Built into the browser. Listen with el.addEventListener("afterscriptexecute", …) — no import required.

Library declarations
JavaScript
addEventListener("afterscriptexecute", fn)

Parameters

ParameterDescription
<script> elementRequired. The script that just finished
Modern pathRequired. script load / error

Return Value

Return ValueDescription
*Fires as an Element event (listener receives the Event object).

JavaScript Examples

Example 1 — addEventListener("afterscriptexecute")

MDN style: attach a listener and note that modern browsers usually never fire it.

JavaScript
function finished(e) {
  console.log("Finished script:", e.target && e.target.nodeName);
}

document.addEventListener("afterscriptexecute", finished);
console.log("Listener attached (may never fire today)");
Try It Yourself

How It Works

  1. Define a handler. Logs the target when the event fires.
  2. Register with addEventListener. Same pattern as any DOM event.
  3. Expect silence today. Most browsers never dispatch this event.
  4. When it did fire. event.target was the script that just finished.

Example 2 — Feature Detection

Never assume the event exists. Check before you depend on it.

JavaScript
const supported = "onafterscriptexecute" in document;
console.log("onafterscriptexecute in document:", supported);

if (supported) {
  document.addEventListener("afterscriptexecute", () => {
    console.log("Legacy path: afterscriptexecute");
  });
} else {
  console.log("Use script load/error events instead");
}
Try It Yourself

How It Works

  1. Probe the handler property. "onafterscriptexecute" in document is a rough signal.
  2. Branch safely. Only register the legacy listener when the property exists.
  3. Fallback path. Otherwise use portable load / error advice.
  4. Still prefer modern APIs. Even if the property exists, engines may not dispatch the event.

Example 3 — Prefer script load

Portable pattern: listen on the script element you create.

JavaScript
const script = document.createElement("script");
script.textContent = "window.__demoRan = true;";

document.body.appendChild(script);

console.log("Prefer load/error over afterscriptexecute");
console.log("after append, __demoRan:", window.__demoRan === true);

// External scripts (usual production case):
// script.src = "/libs/helper.js";
// script.addEventListener("load", () => console.log("executed"));
// script.addEventListener("error", () => console.error("failed"));
// document.head.appendChild(script);
Try It Yourself

How It Works

  1. Create a script node. Inline text runs as soon as you append it.
  2. Append to the document. The browser executes the script immediately.
  3. Confirm the side effect. window.__demoRan becomes true.
  4. For external files. Set src and listen for load / error — the cross-browser replacement.

Browser Support

afterscriptexecute is a Deprecated and Non-standard Gecko Element event (MDN). Other engines never implemented it; modern Firefox no longer dispatches it to web content.

✓ Deprecated · Non-standard

Element afterscriptexecute

Legacy Firefox-only script finish event — do not build features on it.

Legacy Not for new apps
Google Chrome Never implemented
Unavailable
Mozilla Firefox Legacy only · removed / disabled in modern versions
Avoid
Apple Safari Never implemented
Unavailable
Microsoft Edge Never implemented (Chromium)
Unavailable
Opera Never implemented (Chromium)
Unavailable
Internet Explorer No afterscriptexecute support
Unavailable
afterscriptexecute Deprecated

Bottom line: Recognize it in old Gecko code, then migrate. Prefer script load/error events or ES modules.

Frequently Asked Questions

A proprietary Gecko (Firefox) event that fired after a script had been executed (MDN). It is Deprecated and Non-standard, and was never a finished web standard.
No. Prefer the script element’s load and error events, or ES modules. Do not build features on this Gecko-only hook.
No. MDN states the event is not cancelable. The sibling beforescriptexecute could cancel script execution in old Firefox; afterscriptexecute only notified after the fact.
Historically only Firefox (Gecko). Chrome, Safari, and Edge never shipped it. Modern Firefox no longer dispatches it to web content.
In supporting legacy Firefox: document.addEventListener("afterscriptexecute", handler) or document.onafterscriptexecute = handler. Always feature-detect.
A generic Event. There is no special payload beyond a normal Event object.

Next: animationcancel

Learn when a CSS animation is cancelled before it finishes.

animationcancel tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful