Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

option to not load iframes, css and images

247 views
Skip to first unread message

balaji nidadavolu

unread,
Jul 6, 2020, 10:20:40 AM7/6/20
to jsdom
Hi,

   The option resources: "usable" is loading all scripts along with css, images and iframes while using jsdom.fromFile for loading a html document. Is there an option where I can load only a script and not load css, images or iframes. I am trying to dynamically execute some jquery functions on the html in my body, that does not require to load css, images or iframes. I used a window.close() after my operations, but this seems to be an incomplete solution. Can you please suggest on this.

Thank you.

Domenic Denicola

unread,
Jul 6, 2020, 10:27:06 AM7/6/20
to js...@googlegroups.com

--
You received this message because you are subscribed to the Google Groups "jsdom" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jsdom+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jsdom/54244b0f-1571-4e3a-a2b4-87f3b64e0298o%40googlegroups.com.

balaji nidadavolu

unread,
Jul 6, 2020, 10:39:44 AM7/6/20
to jsdom
Thank you for the response. But what are the options to be provided to disable executing css, images and iframes but execute all scripts. I could not find any good examples on custom resource loader. Any pointers would be appreciated.

Thank you.

On Monday, July 6, 2020 at 7:57:06 PM UTC+5:30, Domenic Denicola wrote:

You can use a custom resource loader.

 

From: js...@googlegroups.com <js...@googlegroups.com> On Behalf Of balaji nidadavolu
Sent: Monday, July 6, 2020 10:21
To: jsdom <js...@googlegroups.com>
Subject: option to not load iframes, css and images

 

Hi,

 

   The option resources: "usable" is loading all scripts along with css, images and iframes while using jsdom.fromFile for loading a html document. Is there an option where I can load only a script and not load css, images or iframes. I am trying to dynamically execute some jquery functions on the html in my body, that does not require to load css, images or iframes. I used a window.close() after my operations, but this seems to be an incomplete solution. Can you please suggest on this.

 

Thank you.

--
You received this message because you are subscribed to the Google Groups "jsdom" group.

To unsubscribe from this group and stop receiving emails from it, send an email to js...@googlegroups.com.

balaji nidadavolu

unread,
Jul 7, 2020, 4:28:36 AM7/7/20
to jsdom
Hi,

  Tried below and it worked. it's not loading iframes now.

let jsdom = require('jsdom');
class CustomResourceLoader extends jsdom.ResourceLoader {
fetch(url, options) {
  if (options.element.localName.toLowerCase() === 'iframe' || options.element.localName.toLowerCase() === 'css'
  || options.element.localName.toLowerCase() === 'img') {
return null;
//console.log(`Element ${options.element.localName} is requesting the url ${url}`);
  }
  return super.fetch(url, options);
}
}
const options = {
runScripts: 'dangerously',
resources: new CustomResourceLoader()                   
};
jsdom.JSDOM.fromFile(uri, options).then(function (dom) { }

Thank you Domenic.

Regards
Balaji.
Reply all
Reply to author
Forward
0 new messages