Disable image loading


#1

I’m trying to use Electron to render some HTML, but don’t need to load images. Is there some way I can disable image loading?

I saw the images option, but either that doesn’t work or I’m misunderstanding the purpose of it (not entirely sure what “image support” in the docs refers to).

Thanks in advance for any help you can offer.


#2

You can go through and strip all img elements from the source.


#3

I don’t want to modify the source HTML in any way. I just want to save the CPU cycles and bandwidth of loading images for this particular operation.


#4

I should have been more specific. Run a JS script at the beginning that does a DOM search for instances of img and deletes each of them. Your script will start running when Electron reaches it (well before it gets to any of the images, in computer terms) and the page will be displayed as if there were no images at all.


#5

Look at WebRequest.onBeforeRequest via the BrowserWindow session.
You can cancel anything that looks like an image request.


#6

Presuming you understand how to use BrowserWindow, this works:

mainWindow = new BrowserWindow({width: 1024, height: 768, webPreferences: { nodeIntegration: true,images: false }});
mainWindow.loadURL(‘http://www.google.com’);

The full range of webPreferences doesn’t appear to be supported in a <webview> yet