mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 16:47:34 +00:00
fix(browser): track native frame ports during cleanup (#35346)
Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
@@ -49,6 +49,7 @@ let nextSessionId = 1
|
||||
const observedSessions = new WeakSet<Electron.Session>()
|
||||
const observedContents = new WeakSet<Electron.WebContents>()
|
||||
let frameSweep: NodeJS.Timeout | null = null
|
||||
let framePortCount = 0
|
||||
|
||||
function sessionId(sess: Electron.Session): number {
|
||||
let id = sessionIds.get(sess)
|
||||
@@ -92,9 +93,12 @@ function finish(port: NativePort): void {
|
||||
}
|
||||
port.closed = true
|
||||
ports.delete(port.key)
|
||||
if (port.owner.kind === 'frame') {
|
||||
framePortCount -= 1
|
||||
}
|
||||
port.task?.end()
|
||||
port.connection?.close()
|
||||
if (frameSweep && ![...ports.values()].some((open) => open.owner.kind === 'frame')) {
|
||||
if (frameSweep && framePortCount === 0) {
|
||||
clearInterval(frameSweep)
|
||||
frameSweep = null
|
||||
}
|
||||
@@ -228,6 +232,9 @@ export async function openNativePort(
|
||||
onEvent
|
||||
}
|
||||
ports.set(key, port)
|
||||
if (owner.kind === 'frame') {
|
||||
framePortCount += 1
|
||||
}
|
||||
observeSession(caller.session)
|
||||
if (caller.webContents && owner.kind === 'frame') {
|
||||
observeFrameOwner(caller.webContents)
|
||||
|
||||
Reference in New Issue
Block a user