This code will not work offline

I have a problem with taking this off of chrome. There is a piece of JavaScript code that will only work if I use it on chrome or safari. Instead of loading the animation, it will just show a black screen and will not load anything. However, I have a program called HTML editor that can run JavaScript outside of those Browsers. I have a suspicion feeling it has something to do about the vendors. Is there any way I can change or delete any coding that can help it run off of the program? This is originally from an HTML5 website. This is the code below.

		var lastTime = 0;
		var vendors = ['ms', 'moz', 'webkit', 'o'];
		for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
			window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
			window.cancelAnimationFrame = window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
		if (!window.requestAnimationFrame)
			window.requestAnimationFrame = function(callback, element) {
				var currTime = new Date().getTime();
				var timeToCall = Math.max(0, 16 - (currTime - lastTime));
				var id = window.setTimeout(function() { callback(currTime + timeToCall); }, 
				lastTime = currTime + timeToCall;
				return id;
		if (!window.cancelAnimationFrame)
			window.cancelAnimationFrame = function(id) {

Not sure what that is or how it runs the JS but requestAnimationFrame is a web API.

If you use web APIs you have to run the code inside a runtime that has the APIs. They are not standard JavaScript but additions to the platform your JavaScript runs on, like a browser.

Is there anyway i can still make it work outside of web API

No, if it’s a runtime feature, your runtime must contain it.

Your code does have fallback code for when it isn’t found, but the fallback code is using windows which again is a browser object. I suspect the runtime used by the application you mentioned is Node.js. Node.js is for server-side code and requestAnimationFrame doesn’t make much sense on a server.

The code you posted doesn’t really do anything on its own, so I can’t say how you might use it in Node.js. Not sure if you can use setImmediate.

We would need to know what the code is used for. But if it is rendering stuff to the screen then likely not.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.