fix auto-hide timer: cancel previous timer when showing new labels
- Store timer ID in window global so it can be cancelled - Cancel pending timer when showAriaRefLabels is called again - Cancel pending timer when hideAriaRefLabels is called manually - Existing labels are removed before showing new ones
This commit is contained in:
@@ -256,6 +256,13 @@ export async function showAriaRefLabels({ page, interactiveOnly = true }: {
|
||||
const doc = (globalThis as any).document
|
||||
const win = globalThis as any
|
||||
|
||||
// Cancel any pending auto-hide timer from previous call
|
||||
const timerKey = '__playwriter_labels_timer__'
|
||||
if (win[timerKey]) {
|
||||
win.clearTimeout(win[timerKey])
|
||||
win[timerKey] = null
|
||||
}
|
||||
|
||||
// Remove existing labels if present (idempotent)
|
||||
doc.getElementById(containerId)?.remove()
|
||||
|
||||
@@ -398,8 +405,10 @@ export async function showAriaRefLabels({ page, interactiveOnly = true }: {
|
||||
doc.documentElement.appendChild(container)
|
||||
|
||||
// Auto-hide labels after 5 seconds to prevent stale labels
|
||||
win.setTimeout(() => {
|
||||
// Store timer ID so it can be cancelled if showAriaRefLabels is called again
|
||||
win[timerKey] = win.setTimeout(() => {
|
||||
doc.getElementById(containerId)?.remove()
|
||||
win[timerKey] = null
|
||||
}, 5000)
|
||||
|
||||
return count
|
||||
@@ -423,6 +432,15 @@ export async function showAriaRefLabels({ page, interactiveOnly = true }: {
|
||||
export async function hideAriaRefLabels({ page }: { page: Page }): Promise<void> {
|
||||
await page.evaluate((id) => {
|
||||
const doc = (globalThis as any).document
|
||||
const win = globalThis as any
|
||||
|
||||
// Cancel any pending auto-hide timer
|
||||
const timerKey = '__playwriter_labels_timer__'
|
||||
if (win[timerKey]) {
|
||||
win.clearTimeout(win[timerKey])
|
||||
win[timerKey] = null
|
||||
}
|
||||
|
||||
doc.getElementById(id)?.remove()
|
||||
}, LABELS_CONTAINER_ID)
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
- generic [ref=e55]:
|
||||
- text: "Google offered in:"
|
||||
- link [ref=e56] [cursor=pointer]:
|
||||
- /url: https://www.google.com/setprefs?sig=0_rBKrQWz6eh9LiHviDdhtYH9CsEc%3D&hl=it&source=homepage&sa=X&ved=0ahUKEwiR9Py10O-RAxWpGDQIHWbZLRoQ2ZgBCBU
|
||||
- /url: https://www.google.com/setprefs?sig=0_cJcEG2XLrwZS5WVXl_it8Jb4r40%3D&hl=it&source=homepage&sa=X&ved=0ahUKEwiP_8mU0u-RAxUMMDQIHfYnLGoQ2ZgBCBU
|
||||
- text: Italiano
|
||||
- contentinfo [ref=e58]:
|
||||
- generic [ref=e59]: Italy
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user