fix(snapshotter): remove noscript when javaScriptEnabled is undefined (#30355)

This commit is contained in:
Max Schmitt 2024-04-12 20:26:52 +02:00 committed by GitHub
parent 56a7adeb8a
commit a467312731
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 1 deletions

View file

@ -86,7 +86,8 @@ export class Snapshotter {
eventsHelper.addEventListener(this._context, BrowserContext.Events.Page, this._onPage.bind(this)),
];
const initScript = `(${frameSnapshotStreamer})("${this._snapshotStreamer}", ${!!this._context._options.javaScriptEnabled})`;
const { javaScriptEnabled } = this._context._options;
const initScript = `(${frameSnapshotStreamer})("${this._snapshotStreamer}", ${javaScriptEnabled || javaScriptEnabled === undefined})`;
await this._context.addInitScript(initScript);
await this._runInAllFrames(initScript);
}

View file

@ -1156,3 +1156,39 @@ test('should preserve noscript when javascript is disabled', async ({ browser, s
const frame = await traceViewer.snapshotFrame('page.setContent');
await expect(frame.getByText('javascript is disabled!')).toBeVisible();
});
test('should remove noscript by default', async ({ browser, server, showTraceViewer, browserType }) => {
const traceFile = test.info().outputPath('trace.zip');
const page = await browser.newPage({ javaScriptEnabled: undefined });
await page.context().tracing.start({ snapshots: true, screenshots: true, sources: true });
await page.goto(server.EMPTY_PAGE);
await page.setContent(`
<noscript>Enable JavaScript to run this app.</noscript>
<div>Always visible</div>
`);
await page.context().tracing.stop({ path: traceFile });
await page.close();
const traceViewer = await showTraceViewer([traceFile]);
const frame = await traceViewer.snapshotFrame('page.setContent');
await expect(frame.getByText('Always visible')).toBeVisible();
await expect(frame.getByText('Enable JavaScript to run this app.')).toBeHidden();
});
test('should remove noscript when javaScriptEnabled is set to true', async ({ browser, server, showTraceViewer, browserType }) => {
const traceFile = test.info().outputPath('trace.zip');
const page = await browser.newPage({ javaScriptEnabled: true });
await page.context().tracing.start({ snapshots: true, screenshots: true, sources: true });
await page.goto(server.EMPTY_PAGE);
await page.setContent(`
<noscript>Enable JavaScript to run this app.</noscript>
<div>Always visible</div>
`);
await page.context().tracing.stop({ path: traceFile });
await page.close();
const traceViewer = await showTraceViewer([traceFile]);
const frame = await traceViewer.snapshotFrame('page.setContent');
await expect(frame.getByText('Always visible')).toBeVisible();
await expect(frame.getByText('Enable JavaScript to run this app.')).toBeHidden();
});