I am running a test in headless chrome and part of it I want to prevent the browser from loading the images on the page, the page must be a data url and not a normal page.
I am using headless chrome with the next start command:chrome --headless --remote-debugging-port=9222
I had created the next test to demonstrate what I am trying to achieve. but nothing works...
const CDP = require('chrome-remote-interface');
const fs = require('fs');
CDP(async(client) => {
const {
Page,
Network
} = client;
try {
await Page.enable();
await Network.enable();
await Network.emulateNetworkConditions({
offline: true,
latency: 0,
downloadThroughput: 0,
uploadThroughput: 0
});
await Page.navigate({
url: "data:text/html,<h1>The next image should not be loaded</h1><img src='http://via.placeholder.com/350x150'>"
});
await Page.loadEventFired();
const {
data
} = await Page.captureScreenshot();
fs.writeFileSync((+new Date()) + '.png', Buffer.from(data, 'base64'));
} catch (err) {
console.error(err);
} finally {
await client.close();
}
}).on('error', (err) => {
console.error(err);
});
With puppeteer you can use the args
option for passing the blink-settings argument
const browser = await puppeteer.launch({
args: [
'--blink-settings=imagesEnabled=false'
]
});
You can block images using this flag.
It works on canary and stable.
chrome --headless --remote-debugging-port=9222 --blink-settings=imagesEnabled=false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With