Skip to content

Instantly share code, notes, and snippets.

@kyouheicf
Last active August 11, 2023 14:14
Show Gist options
  • Save kyouheicf/60a6998112f087b2dfa019d1628c2a75 to your computer and use it in GitHub Desktop.
Save kyouheicf/60a6998112f087b2dfa019d1628c2a75 to your computer and use it in GitHub Desktop.
// npm i puppeteer
const puppeteer = require('puppeteer');
puppeteer.launch({
headless: false,
devtools: true,
product: 'firefox',
}).then(async browser => {
const page = (await browser.pages())[0];
await page.setCacheEnabled(false);
await page.waitForTimeout(10000);
// first access
let response = await page.goto('https://your-domain.example.com/pageshieldforcecsp00.html', {
waitUntil: "load",
});
let headers = response.headers();
await page.waitForTimeout(3000);
if (/cf-csp-endpoint/.test(headers["content-security-policy-report-only"])) {
console.log(headers["content-security-policy-report-only"]);
console.log(headers["report-to"]);
await page.close();
await browser.close();
return
}
for (i = 1; i < 20; i++) {
// second access
await page.setCacheEnabled(false);
response = await page.reload({
waitUntil: "load",
})
headers = response.headers();
await page.waitForTimeout(3000);
if (/cf-csp-endpoint/.test(headers["content-security-policy-report-only"])) {
console.log(headers["content-security-policy-report-only"]);
console.log(headers["report-to"]);
await page.close();
await browser.close();
return
}
}
await page.close();
await browser.close();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment