From 44505d575b95b91950905e73f1565fd8a8841ab6 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 May 2025 19:31:51 +0000 Subject: [PATCH 1/2] Initial plan for issue From d7e760aa8efb7046e16fc3aba6cfbd37287a1475 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 23 May 2025 19:40:47 +0000 Subject: [PATCH 2/2] Centralize ID generation to avoid conflicts across instances Co-authored-by: mathis-m <11584315+mathis-m@users.noreply.github.com> --- src/Keyborg.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Keyborg.ts b/src/Keyborg.ts index 0a532b42b..a02651973 100644 --- a/src/Keyborg.ts +++ b/src/Keyborg.ts @@ -21,7 +21,17 @@ interface WindowWithKeyborg extends Window { const _dismissTimeout = 500; // When a key from dismissKeys is pressed and the focus is not moved // during _dismissTimeout time, dismiss the keyboard navigation mode. -let _lastId = 0; +/** + * Generates a unique ID with the specified prefix + * @param prefix - The prefix for the ID ('k' for Keyborg, 'c' for KeyborgCore) + * @returns A unique ID in the format `-` + */ +function getUniqueId(prefix: string): string { + // Use timestamp + counter for uniqueness across instances + const timestamp = Date.now(); + const counter = Math.floor(Math.random() * 10000); + return `${prefix}-${timestamp}-${counter}`; +} export interface KeyborgProps { // Keys to be used to trigger keyboard navigation mode. By default, any key will trigger @@ -48,7 +58,7 @@ class KeyborgCore implements Disposable { private _isNavigatingWithKeyboard_DO_NOT_USE = false; constructor(win: WindowWithKeyborg, props?: KeyborgProps) { - this.id = "c" + ++_lastId; + this.id = getUniqueId("c"); this._win = win; const doc = win.document; @@ -291,7 +301,7 @@ export class Keyborg { } private constructor(win: WindowWithKeyborg, props?: KeyborgProps) { - this._id = "k" + ++_lastId; + this._id = getUniqueId("k"); this._win = win; const current = win.__keyborg;