Skip to content

Commit e93703c

Browse files
committed
👷 only connect to background script when the extension is actually loaded (#3350)
1 parent 92fcbfe commit e93703c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

‎developer-extension/src/panel/backgroundScriptConnection.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ export const onBackgroundDisconnection = new EventListeners<void>()
1010

1111
let backgroundScriptConnection: chrome.runtime.Port | undefined
1212

13-
connectToBackgroundScript()
14-
15-
function connectToBackgroundScript() {
13+
export function connectToBackgroundScript() {
1614
try {
1715
backgroundScriptConnection = chrome.runtime.connect({
1816
name: `devtools-panel-for-tab-${chrome.devtools.inspectedWindow.tabId}`,

‎developer-extension/src/panel/components/app.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@ import { Button, MantineProvider } from '@mantine/core'
22
import type { ReactNode } from 'react'
33
import React, { Suspense, useEffect, useState } from 'react'
44
import { isDisconnectError } from '../../common/isDisconnectError'
5-
import { onBackgroundDisconnection } from '../backgroundScriptConnection'
5+
import { onBackgroundDisconnection, connectToBackgroundScript } from '../backgroundScriptConnection'
66
import { Alert } from './alert'
77
import { Panel } from './panel'
88

99
export function App() {
1010
const [isDisconnected, setIsDisconnected] = useState(false)
1111

1212
useEffect(() => {
13+
connectToBackgroundScript()
14+
1315
const subscription = onBackgroundDisconnection.subscribe(() => setIsDisconnected(true))
1416
return () => subscription.unsubscribe()
1517
}, [])

0 commit comments

Comments
 (0)