I need to remove a tag before taking a screenshot or generating a PDF.
我需要在截取屏幕截图或生成PDF之前删除标记。
Is there any way can lead to this?
有什么办法可以导致这个吗?
I've tried to add page.addScriptTag(options)
and page.addStyleTag(options)
.
我试图添加page.addScriptTag(options)和page.addStyleTag(options)。
I get an error like:
我得到一个错误:
Error when rendering page: TypeError: page.addStyleTag is not a function
1 个解决方案
#1
0
You can use page.evaluate()
to remove the element from within the Page DOM Environment:
您可以使用page.evaluate()从Page DOM环境中删除元素:
await page.evaluate( () =>
{
let example = document.querySelector( '#example' );
example.parentNode.removeChild( example );
});
await page.screenshot( { 'path' : 'screenshot.png' } );
#1
0
You can use page.evaluate()
to remove the element from within the Page DOM Environment:
您可以使用page.evaluate()从Page DOM环境中删除元素:
await page.evaluate( () =>
{
let example = document.querySelector( '#example' );
example.parentNode.removeChild( example );
});
await page.screenshot( { 'path' : 'screenshot.png' } );