I try to take Screenshots of AMP Stories, without the sound and share buttons.
After I found out that there is something called shadow DOM I wonder how to set display : none there:
addStyleTag({content: '.i-amphtml-story-system-layer-buttons { display : none!important }'})
I think I made it to access the shadow DOM like this.
const shadowRootInnerHTML = await page.evaluate(() => {
return document.querySelector("body > amp-story > div").shadowRoot.innerHTML
});
This is what I'm using currently,
const browser = await puppeteer.launch({
slowMo: 250,
args: [
'--disable-infobars',
]
});
const page = await browser.newPage()
await page.emulate({
name: 'iPhone1080x1920',
userAgent: 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1',
viewport: {
width: 360,
height: 640,
deviceScaleFactor: 3,
isLandscape: false
}
});
await page.goto(urlToTest, {
waitUntil: 'networkidle2',
timeout: 0
});
const textContent = await page.evaluate(() => {
return document.querySelector("body > amp-story > div").shadowRoot.innerHTML
});