Skip to content

Commit 413df3d

Browse files
committed
fix: portName stable
1 parent c7b6258 commit 413df3d

File tree

1 file changed

+5
-28
lines changed

1 file changed

+5
-28
lines changed

src/background/router/PortManager.ts

Lines changed: 5 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -158,36 +158,13 @@ export class PortManager {
158158
}
159159

160160

161-
/**
162-
* Generate a unique ID for a port
163-
*/
161+
// Generate a stable ID for a port
164162
private generatePortId(port: chrome.runtime.Port): string {
165-
// Use port name and sender info to create unique ID
166-
const sender = port.sender
167-
const tabId = sender?.tab?.id || 'notab'
168-
const frameId = sender?.frameId || 0
169-
return `${port.name}_${tabId}_${frameId}_${Date.now()}`
163+
// Use port name as the stable ID since it already contains type and executionId
164+
// Port names are unique per connection (e.g., "sidepanel:tab_123", "newtab:tab_123")
165+
return port.name
170166
}
171167

172-
/**
173-
* Get statistics
174-
*/
175-
getStats(): {
176-
totalPorts: number
177-
executionCount: number
178-
portsPerExecution: Record<string, number>
179-
} {
180-
const portsPerExecution: Record<string, number> = {}
181-
for (const [execId, portSet] of this.executionPorts) {
182-
portsPerExecution[execId] = portSet.size
183-
}
184-
185-
return {
186-
totalPorts: this.ports.size,
187-
executionCount: this.executionPorts.size,
188-
portsPerExecution
189-
}
190-
}
191168

192169
/**
193170
* Clean up all ports
@@ -204,4 +181,4 @@ export class PortManager {
204181
this.ports.clear()
205182
this.executionPorts.clear()
206183
}
207-
}
184+
}

0 commit comments

Comments
 (0)