fix(snapshot): remove CSP meta from snapshot (#8698)

This commit is contained in:
Dmitry Gozman 2021-09-03 13:44:02 -07:00 committed by GitHub
parent e2b092c1a0
commit 5d278db17b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 0 deletions

View file

@ -253,6 +253,8 @@ export function frameSnapshotStreamer(snapshotStreamer: string) {
return;
if (this._removeNoScript && nodeName === 'NOSCRIPT')
return;
if (nodeName === 'META' && (node as HTMLMetaElement).httpEquiv.toLowerCase() === 'content-security-policy')
return;
const data = ensureCachedData(node);
const values: any[] = [];

View file

@ -283,6 +283,33 @@ it.describe('snapshots', () => {
expect(await div.evaluate(div => div.scrollTop)).toBe(136);
});
it('should work with meta CSP', async ({ page, showSnapshot, toImpl, snapshotter, browserName }) => {
it.skip(browserName === 'firefox');
await page.setContent(`
<head>
<meta http-equiv="Content-Security-Policy" content="script-src 'none'">
</head>
<body>
<div>Hello</div>
</body>
`);
await page.$eval('div', div => {
const shadow = div.attachShadow({ mode: 'open' });
const span = document.createElement('span');
span.textContent = 'World';
shadow.appendChild(span);
});
const snapshot = await snapshotter.captureSnapshot(toImpl(page), 'meta');
// Render snapshot, check expectations.
const frame = await showSnapshot(snapshot);
await frame.waitForSelector('div');
// Should render shadow dom with post-processing script.
expect(await frame.textContent('span')).toBe('World');
});
it('should handle multiple headers', async ({ page, server, showSnapshot, toImpl, snapshotter, browserName }) => {
it.skip(browserName === 'firefox');