Skip to main content

One post tagged with "chrome-headless"

View All Tags

· One min read
const puppeteer = require('puppeteer');
const pageUrl = 'https://some-url.com';

(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.setRequestInterception(true);

page.on('request', (interceptedRequest) => {
// Don't intercept main document request
if (interceptedRequest.url === pageUrl) {
interceptedRequest.continue();
return;
}

// Intercept if request url starts with https
if (interceptedRequest.url.startsWith('https://')) {
interceptedRequest.continue({
// Replace https:// in url with http://
url: interceptedRequest.url.replace('https://', 'http://'),
});
return;
}

// Don't override other requests
interceptedRequest.continue();
})

await page.goto(pageUrl);
await browser.close();
})();