Skip to content

Commit

Permalink
fix: duplicate port when reloading page, fix #1954
Browse files Browse the repository at this point in the history
  • Loading branch information
Akryum committed Sep 29, 2022
1 parent 3cf35e4 commit f553b0f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/shell-chrome/src/devtools.js
Expand Up @@ -3,6 +3,10 @@
import { initDevTools, setAppConnected } from '@front'
import { Bridge, BridgeEvents } from '@vue-devtools/shared-utils'

let disconnected = false
let connectCount = 0
let retryConnectTimer

initDevTools({

/**
Expand All @@ -16,15 +20,12 @@ initDevTools({
injectScript(chrome.runtime.getURL('build/backend.js'), () => {
// 2. connect to background to setup proxy
let port
let disconnected = false
let connectCount = 0
let timer

const onMessageHandlers = []

function connect () {
try {
clearTimeout(timer)
clearTimeout(retryConnectTimer)
connectCount++
port = chrome.runtime.connect({
name: '' + chrome.devtools.inspectedWindow.tabId,
Expand All @@ -35,7 +36,7 @@ initDevTools({
setAppConnected(false)

// Retry
timer = setTimeout(connect, 1000)
retryConnectTimer = setTimeout(connect, 1000)
})

if (connectCount > 1) {
Expand All @@ -47,7 +48,7 @@ initDevTools({
setAppConnected(false)

// Retry
timer = setTimeout(connect, 5000)
retryConnectTimer = setTimeout(connect, 5000)
}
}
connect()
Expand Down

0 comments on commit f553b0f

Please sign in to comment.