diff --git a/desktop-app/src/renderer/components/Previewer/Device/index.tsx b/desktop-app/src/renderer/components/Previewer/Device/index.tsx index d8ae15959..afd86d470 100644 --- a/desktop-app/src/renderer/components/Previewer/Device/index.tsx +++ b/desktop-app/src/renderer/components/Previewer/Device/index.tsx @@ -205,10 +205,15 @@ const Device = ({ isPrimary, device, setIndividualDevice }: Props) => { return; } const webview = ref.current as Electron.WebviewTag; - - if (webview == null) { + const isOpenedCurrentDevTool = + devtoolsOpenForWebviewId === webview.getWebContentsId(); + if (webview == null || isOpenedCurrentDevTool) { return; } + if (!isOpenedCurrentDevTool && devtoolsOpenForWebviewId !== -1) { + await window.electron.ipcRenderer.invoke('close-devtools'); + dispatch(setDevtoolsClose()); + } await window.electron.ipcRenderer.invoke< OpenDevtoolsArgs, OpenDevtoolsResult @@ -217,7 +222,7 @@ const Device = ({ isPrimary, device, setIndividualDevice }: Props) => { dockPosition, }); dispatch(setDevtoolsOpen(webview.getWebContentsId())); - }, [dispatch, dockPosition]); + }, [devtoolsOpenForWebviewId, dispatch, dockPosition]); const inspectElement = useCallback( async (deviceX: number, deviceY: number) => {