[ANSWERED] JavaScript Actor - What JavaScript is supported inside the Actor?
-
I'm currently trying to use a JavaScript Actor to pull in some data from an API, but I'm having some issues. I'm getting these errors that the functions Im trying to use are not defined. These are built-in JavaScript functions. For example: date().
Any help would be greatly appreciated.
-
Hi there!
Welcome to the Isadora community forum. Happy to help.
When I try to use Date.now() for example it returns the correct result. Could you share some code with us?
Thanks!
-
@juriaan said:
Date.now()
Thanks for the quick reply. This is just one example of something I was trying. My goal is to hit a URL with some additional headers and get back some json. Not reflected here, but what I'm working toward.
function main()
{return fetch('http://api.plos.org/search?q=title:DNA')
.then(response =>{
return response.json();
}).then(data =>{
console.log(data);
})}
-
The Javascript engine in the Javascript actor is the google V8 engine. It has all core ecmascript functions, but does not contain any of the DOM related features (these are part of the browser).
see: https://hackernoon.com/javascr...
You can use the Get URL Text actor to retrieve a websites text (or data from a REST api) and pass this into javascript for parsing.
Or you can use TCP IP actors to interact directly with the server. see: https://www.dusxproductions.co...You will want to use print(); rather than console.log(); to output message to the Monitor window (the .log is part of the browser as well)
These articles will be helpful I think:
https://support.troikatronix.c...
https://support.troikatronix.c...The second one introduces a couple Isadora specific functions for loading external data (or including Libraries.. NOTE libs must be pure Javascript, no DOM etc. Many for Node.JS will work)
-
@dusx This is amazing and super helpful. Thanks!