Electron video won't seek? Custom protocols and HTTP 206 range requests
Short answer: if a <video> served through Electron's protocol.handle jumps back to 0:00 whenever you set currentTime, and video.seekable comes back as 0 to 0, your handler is answering range requests with a plain 200. Read the Range header yourself and answer 206 Partial Content with Content-Range, Content-Length and Accept-Ranges: bytes, plus a 416 with Content-Range: bytes */<size> for a range past the end. Register the scheme with standard: true and stream: true too. Once the handler speaks ranges, the video seeks.
This bug lived in the editor of Framok, my screen recorder for Windows, built on Electron, until 0.7.11 on 27 Sep. Here's what it looked like, why the handler from Electron's own docs caused it, the handler that replaced it, and the test that seeks a real video in a hidden window.
The timeline that always went back to the start
Framok's editor plays your recording above a timeline. Click anywhere on the timeline and the playhead should jump there. Drag along it and the video should scrub.
Instead, every click and every drag snapped the playhead back to 0:00. Playing from the start worked fine, so a recording looked healthy right up until you tried to move around in it.

It broke something less obvious too. Fill and Stack, the ways Framok makes tall and square videos from a wide screen, frame the button or field under each click. To find it, the editor seeks a hidden copy of the video to the moment of each press and reads that frame. With seeking broken, every one of those seeks landed on frame 0, so every press was matched against the first frame of the recording. That looked like a framing bug, and it took the timeline bug to explain it.
How recordings reach the editor
Rather than load recordings from file:// URLs, Framok registers its own scheme, media://, and serves them through it:
protocol.registerSchemesAsPrivileged([
{ scheme: 'media', privileges: { standard: true, secure: true, supportFetchAPI: true, stream: true, bypassCSP: true, corsEnabled: true } },
]);
A recording's file is then media://rec/<recording id>/<file>. The handler, up to 0.7.10, did what the first example in Electron's protocol docs does, handing the request to net.fetch on a file:// URL (Electron):
const p = path.join(RECORDINGS_DIR(), id, file);
const res = await net.fetch(pathToFileURL(p).toString(), { headers: request.headers });
const headers = new Headers(res.headers);
headers.set('Access-Control-Allow-Origin', '*');
return new Response(res.body, { status: res.status, statusText: res.statusText, headers });
It even passes the request's headers through, Range included. Playback worked, which is why it looked right.
What the answer actually said
A video element asks for the file in byte ranges, so it can fetch the part it needs when you seek. MDN describes the Range header as indicating "the part of a resource that the server should return", answered with 206 Partial Content when the server sends ranges and 416 Range Not Satisfiable when they're invalid (MDN).
On Electron 44.2.0, which Framok ran at the time, net.fetch on a file:// URL read the requested byte range but answered 200, with no Content-Length, no Content-Range and no Accept-Ranges. The same MDN page explains how that reads to a browser: "A server that doesn't support range requests may ignore the Range header and return the whole resource with a 200 status code."
So Chromium's media stack took the recording for a stream it couldn't jump around in. video.seekable, which "represents the ranges of the media resource, if any, that the user agent is able to seek to" (MDN), came back as 0 to 0. Every seek went to the only place it could: the start.
I wasn't the first. Electron issue #38749, "video files not seekable with protocol.handle", was opened on 13 Jun 2023 and is still open. Same symptoms: setting currentTime jumps back to zero and seekable.end() is always 0. The comments point at two separate causes. A scheme that isn't registered as standard has no proper origin, so the follow up range requests fail. And, as one commenter puts it, "the handler itself still has to honor Range and answer with 206, Content-Range and Content-Length." Framok's scheme was already standard. The handler was the problem.
The fix: answer ranges yourself
0.7.11 stopped forwarding to net.fetch and serves the file directly, in a small module of its own. First, the Range header:
function parseRange(header, size) {
if (!header) return null;
const m = /^\s*bytes\s*=\s*(\d*)\s*-\s*(\d*)\s*$/i.exec(String(header));
if (!m) return null;
const [, a, b] = m;
if (a === '' && b === '') return null;
if (size === 0) return 'unsatisfiable';
let start, end;
if (a === '') {
// Suffix range: the last b bytes.
const n = Number(b);
if (n === 0) return 'unsatisfiable';
start = Math.max(0, size - n);
end = size - 1;
} else {
start = Number(a);
end = b === '' ? size - 1 : Math.min(Number(b), size - 1);
if (start >= size || end < start) return 'unsatisfiable';
}
return { start, end };
}
It handles the three single range forms MDN lists: bytes=0-499, bytes=900- to the end, and bytes=-100 for the last 100 bytes. A request for several ranges at once gets the whole file with a 200, which MDN allows for a server that doesn't support them.
Then the answer:
const range = parseRange(rangeHeader, size);
if (range === 'unsatisfiable') {
headers.set('Content-Range', 'bytes */' + size);
return new Response(null, { status: 416, headers });
}
const { start, end } = range || { start: 0, end: size - 1 };
const length = size === 0 ? 0 : end - start + 1;
headers.set('Content-Length', String(length));
if (range) headers.set('Content-Range', 'bytes ' + start + '-' + end + '/' + size);
const body = length ? Readable.toWeb(fs.createReadStream(file, { start, end })) : null;
return new Response(body, { status: range ? 206 : 200, headers });
Accept-Ranges: bytes, the Content-Type and Last-Modified are set on every answer before this. The details that matter:
- Content-Range is inclusive and zero based.
bytes 100-199/1000is 100 bytes. MDN: the start and end are "zero-indexed & inclusive" (MDN). - Content-Length is the length of the part, not the file.
- A range past the end gets 416 with
bytes */<size>, so the player knows how big the file really is. - The body is a stream of just that slice, read straight from disk, so a long recording never has to sit in memory.
The handler itself shrank to one line after its path checks:
return mediaFile.serveFile(p, request.headers.get('range'), { 'Access-Control-Allow-Origin': '*' });
The Access-Control-Allow-Origin header stays because of the Fill and Stack frame reading: the editor draws frames of the recording into a canvas and reads the pixels back, and a cross origin video without it would taint the canvas.
Testing a real seek
Unit tests on the parser are easy and I wrote them: open ranges, closed ranges, ranges that run past the end, suffix ranges, a suffix bigger than the file, a start past the end, an end before the start, an empty file, multiple ranges and a unit that isn't bytes. Another set checks the answers: 200 with the full length when there's no range, 206 with bytes 100-199/1000 and a length of 100 for a middle slice, 416 with bytes */1000 past the end, 404 for a missing file or a folder.
None of that proves a video seeks. So the last test does it for real:
- ffmpeg makes a 4 second, 320 by 180 test clip at 30 frames a second.
- A hidden Electron window registers
media://with the same privileges, serves the clip through the sameserveFile, and loads it into a muted video element. - It seeks to 2.5, 0.8, 3.6 and 1.7 seconds, waiting for
seekedeach time, then fires 20 seeks without waiting, the way a drag along the timeline does.
const seekTo = (t) => new Promise((res) => {
const done = () => { clearTimeout(timer); res(v.currentTime); };
const timer = setTimeout(done, 5000);
v.addEventListener('seeked', done, { once: true });
v.currentTime = t;
});
The test passes only if seekable reaches past 3.5 s, every seek lands within 0.1 s of where it was asked to go, and the scrub settles on 3.0 s.
One more test reads main.js and fails if the media:// handler ever calls net.fetch again, so the bug can't come back through a tidy up.
What I'd tell anyone doing this
- Check
video.seekablefirst. If it's 0 to 0 on a file you know is whole, the problem is the response headers, not your player code. - Don't trust a forwarded fetch to speak ranges. Look at the status and headers your handler actually returns for a request with
Rangeon it. - Register the scheme as
standardas well, or the range requests after the first can fail for a different reason. - Test the seek in a real window. Header tests pass while the video still won't move.
The editor in Framok today
Clicking or dragging on the timeline moves the playhead where you point, and Fill and Stack read the frame each click actually happened on, so they frame what you clicked. The editor plays every take, with or without a licence. More on the Electron side of Framok: drawing my own cursor covers the overlay windows kept out of the capture, and shipping an Electron app to the Microsoft Store covers MSIX packaging.
Where Framok doesn't help
- Not a general video editor. It edits recordings made in Framok: trim, speed, zooms, cursor, background, webcam bubble and export.
- Windows only. Windows 10 or later, 64 bit. A Mac version is coming, with an email waitlist on framok.com.
- The download isn't code signed yet, so SmartScreen warns the first time. Click More info, then Run anyway.
Framok is $29 once for the life of the product, or $5 a month and cancel any time. Both cover 2 of your own PCs, and the download is free for 7 days with every feature, no card and no account.
Anyone else serving video through a custom Electron protocol? I'd like to know whether you answer ranges yourself or found a way to make net.fetch do it.
Sources
- Electron, protocol:
protocol.handle, thenet.fetchexample andregisterSchemesAsPrivileged - Electron issue #38749, "video files not seekable with protocol.handle"
- MDN, Range, 206 Partial Content, Content-Range and HTMLMediaElement.seekable
- Framok's changelog (0.7.11), commit b76e197 (27 Sep 2026), and src/main/media-file.js, test/media-file.test.js and test/media-seek.electron.js in the recorder repo