The Problem
Unfortunately there is no frame API for us to use - Firefox has some experimental features, but other than that we can only deal with time and how the browser handles frame decoding as well as frame rate conversion. See below for an update.
For example, the browser may or may always convert/normalize to 30 fps, and if so may or may not assume drop-frame (for 29.97/59.94 fps/NTSC). Over time this will affect the frame count and will eventually show as offsets as there is no true link between time and frame count.
In addition there could be rounding errors due to the integer based conversion and also potentially depending on the start position in the video. There are also different solutions to how video is decoded under the hood depending on the broswer, for example, Chrome uses FFMpeg underneath, Firefox uses whatever is available in the OS* (for MP4 encoded videos) and so forth.
Possible solution
(Update: forgot to mention -) There is the Media Source Extensions API which support the VideoPlaybackQuality
object. This has currently [support in Chrome and IE (on Windows 8+) as well as in Firefox.
To use you can call it directly on the HTMLVideoElement:
var q = video.getVideoPlaybackQuality();
Then read out the values using its property:
var frames = q.totalVideoFrames;
Just be aware of that this value may accumulate all frames regardless of the actual play position. You can perhaps get around this working with MSE directly. It's a little more tedious to setup and handle, but this link provides a good starting point in case you're unfamiliar with MSE.
An alternative idea would be to encode a special bar-code in the video, then read it using canvas. It would be the equivalent on an actual SMPTE time-code, but this would require an overlay being visible in the video to some degree (ala the old way of encoding tele-text into the over-scan area of the video). If the video is full-frame other problems will arise such as false detection depending on colors used for the coding (or make a solid background for it).
*) may have changed in recent versions after Cisco released their mp4 solution for free.