
Announcements
When I run the following code to capture ld+json content, it returns the ld+json content as well as JS code at the end of the JSResult variable. This prevents the Convert JSON to customer object action from running. Any ideas why that code is being returned and how to prevent it?
Thanks, John
Run JavaScript function on web page JavaScript Function:
function ExecuteScript() {
var headings = document.evaluate("//script[contains(., 'gtin')]", document, null, XPathResult.ANY_TYPE, null );
var thisHeading = headings.iterateNext();
var result = "";
while (thisHeading) {
result += thisHeading.innerText;
thisHeading = headings.iterateNext();
}
return result;
}
Weird code at end of JSResult variable.
var result = undefined; try{ result = (function ExecuteScript() {
var headings = document.evaluate("//script[contains(., 'gtin')]", document, null, XPathResult.ANY_TYPE, null );
var thisHeading = headings.iterateNext();
var result = "";
while (thisHeading) {
result += thisHeading.innerText;
thisHeading = headings.iterateNext();
}
return result;
})();;}catch(e){}; document.documentElement.setAttribute("result", result); document.documentElement.setAttribute("complete", "true");
It appears that PAD may have a bug with its JavaScript action. The above code appears to run an extra loop in the while and for some reason echos the action's code. To prevent this I modified the loop as follows. This prevents the echo of the action's code to be included in the results.
John
function ExecuteScript() {
var txtJSON= "[";
var headings = document.evaluate("//script[contains(., 'gtin')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
for(var i = 0; i < headings.snapshotLength-1; i++) {
txtJSON += headings.snapshotItem(i).innerText;
if (i < headings.snapshotLength-2) {
txtJSON += ", ";
}
}
txtJSON += "]";
return txtJSON;
}