var rules = [{ "name": "Fetching multiple thing from the content page with context.findHtml", "url": "https://scotch.io/tutorials/javascript-promises-for-dummies", "before": function(resolve, context) { // Lets fetch two headlines from the page // 1. Generate an array of Promises. var promises = [ context.findHtml("#toc-understanding-promises"), context.findHtml("#toc-creating-a-promise") ]; // Promise.all will resolve when ALL promises in the argument are resolved // You'll get an array in the .then() function containing one element per promise. Promise.all(promises).then(function(dataFromAllPromises) { // dataFromAllPromises[0] = result of context.findHtml("#toc-understanding-promises") // dataFromAllPromises[1] = result of context.findHtml("#toc-creating-a-promise") // Now transform the data (eg. remove tags) and resolve the "before" function to // make the data available in value functions. resolve(dataFromAllPromises); }); }, "fields": [{ "selector": "#aa-search-input", "value": function($domElement, dataFrombeforeFunction) { return "#toc-understanding-promises : " + dataFrombeforeFunction[0] + " #toc-creating-a-promise : " + dataFrombeforeFunction[1]; } }] } ];