DomParser in Lambda functions always not defined
Options
Vlad B
Member ✭
I am trying out the Lambda Functions for an HTML transformation, and am using the DOMParser
However I get "DOMParser is not defined" as an error. i tried two options
a basic one with no success:
var htmlDoc = new DOMParser().parseFromString("","text/html");
and my code which throws same error:
var parser = new DOMParser();
var sourceData = $var.sample;
var htmlDoc = parser.parseFromString(sourceData, 'text/xml');
regardless of what I do, I get the not defined error. Any thoughts would be appreciated.
However I get "DOMParser is not defined" as an error. i tried two options
a basic one with no success:
var htmlDoc = new DOMParser().parseFromString("","text/html");
and my code which throws same error:
var parser = new DOMParser();
var sourceData = $var.sample;
var htmlDoc = parser.parseFromString(sourceData, 'text/xml');
regardless of what I do, I get the not defined error. Any thoughts would be appreciated.
Comments
-
DOMParser is provided by on a browser, but not by nodejs, which is what the Xano lambda runs on. So it's not available out of the box. Preloaded libraries are loaded into global scope and listed on the documentation: https://docs.xano.com/working-with-data/lambdas-javascript
There are node-side packages (e.g. jsdom) that solve this problem, but the lambda functionality is a little locked down at the moment - loading arbitrary libraries sometimes works with hack-y approaches like loading webpacked javascript into the lambda, or loading external javascript via a fetch request and evaluating it. (I've made the UI cry a bit with these hacks). Glad to give such an end-run a try with jsdom to see if that helps you: https://www.npmjs.com/package/jsdom -
Hi Ray, thank you for your reply! I am pondering if I am going to try and use workarounds or just do it outside Xano for the moment. Your approaches, while detailed, are as you said "hacks", and I am trying to stay away from this as much as possible.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback