hardening: namespace snapshot cache keys to avoid sentinel collisions

Use 'page' and 'locator:' prefixed keys instead of raw '__page__' sentinel,
preventing theoretical collision if a CSS selector equals '__page__'.
This commit is contained in:
Tommy D. Rossi
2026-02-28 14:30:16 +01:00
parent ece02cd4ad
commit 2d7e293d1f
2 changed files with 3 additions and 3 deletions
+2 -2
View File
@@ -26,9 +26,9 @@ function isRegExp(value: any): value is RegExp {
function getSnapshotKey(locator: Locator | Page): string {
if (isPage(locator)) {
return '__page__'
return 'page'
}
return locator.selector()
return `locator:${locator.selector()}`
}
export async function getCleanHTML(options: GetCleanHTMLOptions): Promise<string> {
+1 -1
View File
@@ -790,7 +790,7 @@ export class PlaywrightExecutor {
const shouldCacheSnapshot = !frame
// Cache keyed by locator selector so full-page and locator-scoped snapshots
// don't pollute each other's diff baselines
const snapshotKey = locator ? locator.selector() : '__page__'
const snapshotKey = locator ? `locator:${locator.selector()}` : 'page'
let pageSnapshots = this.lastSnapshots.get(resolvedPage)
if (!pageSnapshots) {
pageSnapshots = new Map()