A simple implementation, with "frames in a 1s interval". You can smoothen it out using, say, frames in a 5s interval
// variables accessible from within function(frame)
var frameCount = 0;
var currentSecond = 0;
var frameRate = 0;
// within function(frame), called with current time on each new frame
function updateFrameRate(time) {
var second = Math.floor(time / 1000); // ms to integer seconds
if (second != currentSecond) {
frameRate = frameCount;
frameCount = 0;
currentSecond = second;
}
frameCount ++;
}