The afterscriptexecute event once fired after a script finished running in Firefox. Learn what it meant, why it is deprecated and non-standard, how to feature-detect it safely, how it differed from beforescriptexecute, and which portable APIs to use instead—with five examples and try-it labs.
01
Kind
Instance event
02
Type
Event
03
Cancelable
No
04
Status
Deprecated · Non-standard
05
Engine
Legacy Gecko only
06
Modern path
script.onload
Fundamentals
Introduction
Sometimes you want to know when a <script> has finished executing—for logging, analytics, or coordinating code that depends on that script. Early Gecko experiments added a pair of proprietary events: beforescriptexecute (before run) and afterscriptexecute (after run).
afterscriptexecute answered a simple question: did this script just finish? It was never adopted by other browsers, never finished as a standard, and MDN warns not to rely on it.
⚠️
Deprecated & non-standard
Learn this event for legacy Firefox code and interviews. For new apps, use standard script lifecycle hooks (load / error on the script element) or ES modules instead of Gecko-only events.
Concept
Understanding afterscriptexecute
An instance event on Element (listened on document or other nodes in supporting Gecko). It notified you after script execution completed.
Fires after a script has been executed (legacy Firefox).
Not cancelable — you cannot undo execution after the fact.
Generic Event — no special payload properties.
Sibling — beforescriptexecute ran earlier and could cancel execution.
Status — Deprecated and Non-standard on MDN; not part of any specification.
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property (legacy Firefox only):
For modules, use <script type="module"> and normal import / top-level await so dependencies are explicit. To watch scripts being inserted into the DOM, use MutationObserver—not proprietary execute events.
"onafterscriptexecute" in document (weak; still prefer alternatives)
Modern replace
script.addEventListener("load", fn)
MDN status
Deprecated · Non-standard
Snapshot
🔍 At a Glance
Four facts to remember about afterscriptexecute.
Event type
Event
Generic
Cancelable
no
After the fact
Standard?
no
Non-standard
New code?
avoid
Use script load
Hands-On
Examples Gallery
Examples follow MDN Element: afterscriptexecute event and show safe feature detection plus modern replacements. In most current browsers the proprietary event will never fire—the labs still teach the patterns clearly.
📚 Getting Started
Register handlers the MDN ways (legacy Gecko).
Example 1 — addEventListener("afterscriptexecute")
MDN style: listen on document and log when a script finishes (where supported).
JavaScript
document.addEventListener("afterscriptexecute", (event) => {
console.log("afterscriptexecute fired");
console.log("target:", event.target && event.target.nodeName);
});
// In legacy Firefox, inserting/running a <script> could fire this.
// In modern browsers it typically never fires.
Listener attached (event may never fire in modern browsers)
How It Works
You register the same way as any other DOM event. Support is the hard part: without legacy Gecko behavior, the handler sits idle.
Example 2 — onafterscriptexecute Property
MDN’s alternate style using the event handler property.
JavaScript
document.onafterscriptexecute = (event) => {
console.log("Script finished (onafterscriptexecute)");
};
// Assigning again replaces the previous handler.
// Prefer addEventListener when you need multiple listeners.
onafterscriptexecute in document: false
Use script load/error events instead
How It Works
Presence of the handler property is a rough signal. Even when the property exists, modern engines may not dispatch the event—so still prefer portable APIs.
Example 4 — Pair with beforescriptexecute
In old Gecko, before/after formed a bracket around script execution.
JavaScript
document.addEventListener("beforescriptexecute", () => {
console.log("1) before script execute");
});
document.addEventListener("afterscriptexecute", () => {
console.log("2) after script execute");
});
// Historical order in supporting Firefox:
// beforescriptexecute → script runs → afterscriptexecute
// Both events are deprecated and non-standard.
Prefer load/error over afterscriptexecute
demo flag set via inline script: false
after append, __demoRan: true
How It Works
Inline scripts run as soon as they are inserted. External scripts expose a reliable load event when fetch + execute succeed. That is the cross-browser replacement for proprietary after-execute notifications.
Applications
🚀 Common Use Cases
Understanding legacy Firefox / Gecko code that monitored script execution.
Migrating old extensions or pages off proprietary script-execute events.
Interview / history knowledge of early HTML script lifecycle proposals.
Teaching why feature detection and standards matter for DOM events.
Choosing load / error or ES modules for real production work.
Under the Hood
🔧 How It Works
1
Script is about to run
Browser prepares to execute a <script> element.
Prepare
2
Script executes
JavaScript runs to completion (or throws).
Run
3
afterscriptexecute (legacy)
Old Gecko dispatched a non-cancelable Event.
Notify
4
✓
Prefer standard load hooks
Use load / error or modules in new code.
Important
📝 Notes
MDN: Deprecated and Non-standard — avoid in production.
Not cancelable; sibling beforescriptexecute was the cancelable one.
Proprietary to Gecko; never a cross-browser API.
Modern Firefox stopped shipping useful web-facing support for these events.
afterscriptexecute is a deprecated, non-standard Gecko event. Logos use the shared browser-image-sprite.png sprite from this project. Other engines never implemented it; modern Firefox no longer dispatches it to web content. Prefer scriptload/error events.
✓ Deprecated · Non-standard
Element afterscriptexecute
Do not build features on this event. Use it only to understand or migrate legacy Firefox code.
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: Feature-detect if you must touch legacy Gecko code. For new work, use script load/error events or ES modules.
Wrap Up
Conclusion
afterscriptexecute once told Firefox pages that a script had finished running. Today it is a deprecated, non-standard footnote: useful for reading old code, not for shipping new products.
Feature-detect before touching legacy Gecko-only APIs
Document why any remaining legacy listener exists
Plan migration off proprietary script-execute events
❌ Don’t
Build new features on afterscriptexecute
Assume Chrome, Safari, or Edge ever supported it
Expect preventDefault() to undo execution
Confuse it with the standard load event
Treat non-standard Gecko events as future-proof
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about afterscriptexecute
Legacy Gecko “script finished” signal — prefer standard load hooks now.
5
Core concepts
📄01
After script runs
legacy notify
Event
⚠️02
Deprecated
avoid new use
Status
🚫03
Non-standard
Gecko only
Compat
🚫04
Not cancelable
after the fact
API
🚀05
Replace
script load
Modern
❓ Frequently Asked Questions
It is a proprietary Gecko (Firefox) DOM event that fired after a script element had finished executing. MDN marks it Deprecated and Non-standard. It was never a finished web standard.
No. Prefer portable APIs such as script.onload / script.onerror for classic scripts, the load event on the script element, module scripts with type="module", or MutationObserver when you need to watch scripts being inserted.
No. MDN states the event is not cancelable. Its sibling beforescriptexecute could cancel script execution in old Firefox; afterscriptexecute only notified after the fact.
Historically only Firefox (Gecko). Other major browsers never shipped it. Modern Firefox stopped dispatching it to web content (around Firefox 144) and later removed the implementation.
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.
Did you know?
Mozilla later unshipped beforescriptexecute and afterscriptexecute from web content because they were non-standard and unused by other browsers. Script blockers that once relied on them moved to portable techniques such as changing a script’s type via MutationObserver.