From 6316c7da8e2826a736e0ad906f13cde43bd26c86 Mon Sep 17 00:00:00 2001 From: Maxim Laikine <40576301+lamaks@users.noreply.github.com> Date: Mon, 10 Jun 2024 11:40:48 -0700 Subject: [PATCH] Restricted page snapshot size (#2552) #### Details Restricted page snapshot size #### Pull request checklist - [ ] Addresses an existing issue: Fixes #0000 - [ ] Added relevant unit test for your changes. (`yarn test`) - [ ] Verified code coverage for the changes made. Check coverage report at: `/test-results/unit/coverage` - [ ] Ran precheckin (`yarn precheckin`) - [ ] Validated in an Azure resource group --- packages/scanner-global-library/src/page.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/scanner-global-library/src/page.ts b/packages/scanner-global-library/src/page.ts index afc3beeef..af64dc321 100644 --- a/packages/scanner-global-library/src/page.ts +++ b/packages/scanner-global-library/src/page.ts @@ -215,8 +215,17 @@ export class Page { } public async getPageSnapshot(): Promise { + const maxSnapshotSize = 10 * 1024 * 1024; try { - const { data } = await this.devToolsSession.send(this.page, 'Page.captureSnapshot', { format: 'mhtml' }); + let { data } = await this.devToolsSession.send(this.page, 'Page.captureSnapshot', { format: 'mhtml' }); + const length = Buffer.byteLength(JSON.stringify(data), 'utf8'); + if (length > maxSnapshotSize) { + this.logger?.logWarn(`Page snapshot exceeded maximum supported size of ${maxSnapshotSize / (1024 * 1024)} MB`, { + snapshotSize: length.toString(), + }); + + data = ''; + } return data; } catch (error) {