How can we to extend element methods in JSDOM to all opened pages?
// load the module and few pages
const JSDOM = require("jsdom").JSDOM;
var dom1 = new JSDOM("<p>1st</p><p>2nd</p>");
var dom2 = new JSDOM("<p>1st</p><p>2nd</p>");
...
// add methods such as: map, filter, searchText...
var window = dom1.window;
window.NodeList.prototype.map =
function (cb) { return Array.from(this).map(cb) };
...
// Execution:
dom1.window.document.querySelectorAll('p').map(p=> p.textContent);
// returns: [ '1st', '2nd' ]
dom2.window.document.querySelectorAll('p').map(p=> p.textContent);
// throws an error
Is it possible to extend NodeList ones, without loading it for every new document?
Something more like:
JSDOM.installedInterfaces.NodeList.prototype.map = ...