👀 Live Preview
Load the video — when enough is buffered to play through, status updates:
Waiting for canplaythrough…

The oncanplaythrough attribute is an inline event handler that runs JavaScript when the canplaythrough event fires. That happens on <audio> and <video> when the browser estimates enough media is buffered to play through to the end without stopping to load more data. Use it to hide loading overlays, enable confident autoplay, or show “ready” status. It is stronger than oncanplay (which only means playback can start) but is still an estimate—not a guarantee on slow networks.
Inline JS.
Media event.
Buffer estimate.
Start vs through.
Preferred way.
Property API.
oncanplaythrough AttributeThe primary purpose of oncanplaythrough is to react when buffering looks sufficient for uninterrupted playback. You might remove a full-screen loader, enable a custom player, or start autoplay (where policy allows). It typically fires after canplay once more of the file has buffered.
The old reference mixed up titles (calling an example “onprogress”) and function names. Also remember: canplaythrough is the browser’s estimate, not a promise that buffering will never pause. Seeking or poor connectivity can still trigger waiting later.
Production code should use video.addEventListener("canplaythrough", handler). Inline oncanplaythrough works for learning but separates concerns less cleanly.
Set oncanplaythrough on audio or video, or assign element.oncanplaythrough:
<script>
function handleCanPlayThrough() {
console.log("Media can play through.");
}
</script>
<video controls oncanplaythrough="handleCanPlayThrough()">
<source src="clip.mp4" type="video/mp4">
</video>canplaythrough event fires.<audio> and <video> media elements.media.oncanplaythrough = function() { … }.media.addEventListener("canplaythrough", handler).canplay in the media load sequence.The oncanplaythrough attribute accepts a string of JavaScript code:
oncanplaythrough="handleCanPlayThrough()" — Call a named function.oncanplaythrough="hideLoader()" — Inline statement.video.oncanplaythrough = () => { … } assigns the handler.const video = document.getElementById("clip");
video.addEventListener("canplaythrough", () => {
document.getElementById("loader").hidden = true;
});
video.addEventListener("canplay", () => {
document.getElementById("playBtn").disabled = false;
});| Event | When it fires | Handler |
|---|---|---|
canplay | Enough data to start | oncanplay |
canplaythrough | Can play to end (estimate) | oncanplaythrough |
loadeddata | First frame ready | onloadeddata |
| Hide full loader | In canplaythrough handler | Common pattern |
| Enable play sooner | Use oncanplay instead | Lighter threshold |
| Target | Supported? | Notes |
|---|---|---|
<audio> | Yes | Inline oncanplaythrough on video |
<video> | Yes | Most common use |
<source> | No | Event fires on parent media element |
<input>, <img> | No | Not media canplay events |
oncanplay vs oncanplaythrough vs onloadeddata| Handler | When it fires | Typical use |
|---|---|---|
onloadeddata | First frame of media available | Show poster / first frame |
oncanplay | Enough buffered to start | Enable play button, hide loader |
oncanplaythrough | Enough buffered to play through | Autoplay long content confidently |
Inline oncanplaythrough on video, addEventListener, and comparison with oncanplay.
Load the video — when enough is buffered to play through, status updates:
Waiting for canplaythrough…
Run a function when playback can continue without stopping:
<video controls oncanplaythrough="handleCanPlayThrough()">
<source src="clip.mp4" type="video/mp4">
</video>
<script>
function handleCanPlayThrough() {
console.log("Media can play through.");
}
</script>The browser fires canplaythrough on the video element when buffering looks sufficient. The inline oncanplaythrough attribute wires up the handler.
Attach the handler with addEventListener:
<script>
document.getElementById("clip").addEventListener("canplaythrough", function () {
console.log("Video can play through.");
});
// Or property form:
document.getElementById("clip").oncanplaythrough = function () { /* … */ };
</script>Register the listener once at page load. When buffering looks sufficient, canplaythrough runs your readiness code.
Listen for both events on the same element:
audio.addEventListener("canplay", () => { /* can start */ });
audio.addEventListener("canplaythrough", () => { /* can play through */ });Use oncanplay to enable play early; use oncanplaythrough when you need confidence before autoplay or removing a full loader.
canplay to enable controls, not surprise playback.controls attribute supports keyboard users; custom players need full keyboard support.Browser fetches the file.
Enough to start playback.
Estimate improves.
Play-through ready.
The canplaythrough event and oncanplaythrough handler are supported in all modern browsers on <audio> and <video> elements — Chrome, Firefox, Safari, and Edge.
oncanplaythrough supportAll major browsers fire the underlying event and honor the oncanplaythrough handler attribute.
Bottom line: Universal support on media elements. Test canplay vs canplaythrough timing with network throttling.
oncanplaythrough.oncanplay if you only need to enable play sooner.audio/video for unsupported browsers.The oncanplaythrough attribute runs JavaScript when the browser estimates enough media is buffered and the canplaythrough event fires on audio or video. Use it to hide full loaders and enable confident playback UI.
Prefer addEventListener("canplaythrough", …), understand it is stronger than oncanplay but still an estimate, and handle waiting if buffering pauses later.
oncanplaythroughBookmark these before wiring your next event handler.
canplaythrough fires.
EventMedia only.
ScopeAfter canplaythrough.
PatternPreferred.
ModernNot a guarantee.
Notecanplaythrough event fires — when the browser estimates enough media is buffered to play through without stopping.audio and video elements. The event fires on the media element loading the resource.oncanplay means playback can start. oncanplaythrough means the browser estimates uninterrupted playback is possible.waiting later.media.addEventListener("canplaythrough", …). Inline oncanplaythrough works for simple demos.canplay, once more data has buffered. For short files they may fire close together.Practice inline oncanplaythrough, addEventListener, and comparison with oncanplay in the Try It editor.
5 people found this page helpful