If the script runs in the CoSpaces web app but it doesn't run in the smartphone app

Problem:

JavaScript is an evolving language and new features are added to the language regularly. It’s now in its seventh edition (ECMAScript 2016). However, that doesn’t mean we can use all the latest features without any issues.

There are many JavaScript engines out there and not all engines support all features of the newest JavaScript version. Different browsers use different JavaScript engines. Additionally, the CoSpaces mobile app uses a different engine than your browser.

An example: If you use the latest features of JavaScript in your code, the script may be interpreted just fine in your browser. However, the same code might throw an error in another browser or on mobile devices. In this case, your script will not be executed as expected there.


Solution:

To be sure that your script runs just fine in most modern browsers and on mobile devices, don’t use features newer than specified in JavaScripts fifth edition (ECMAScript 5.1).


Better solution:

Switch the coding editor to TypeScript. The reason is that the TypeScript transpiler will generate JavaScript code according to older specifications. Therefore it’s easily interpretable on mobile and you can use new features provided by the TypeScript language without to worry.


Caution:

Also, do not use Web APIs. These objects/functions are exposed by the browser. But the CoSpaces mobile app isn’t running in a browser. Therefore it can’t work there.
Only use objects and methods provided by the CoSpaces Scripting API as well as JavaScript’s built-in objects and functions/methods listed below.