From 644fc9b195770a053c5edd244c762f69fae0814a Mon Sep 17 00:00:00 2001 From: abose Date: Wed, 18 Dec 2024 17:48:16 +0530 Subject: [PATCH] fix: clicking on prevent defaulted A tags in dekstop live preview opens browser tab --- .../LivePreviewTransportRemote.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js b/src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js index 646bc7c033..8844ecd020 100644 --- a/src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js +++ b/src/LiveDevelopment/BrowserScripts/LivePreviewTransportRemote.js @@ -304,17 +304,19 @@ // an iframe(except for the intel mac bug) // in normal browsers, we dont need to do this and the borwser will do its thing. const href = getAbsoluteUrl(targetElement.getAttribute('href')); - window.parent.postMessage({ - handlerName: "ph-liveServer", - eventName: 'embeddedIframeHrefClick', - href: href - }, "*"); - // in intel mac desktop, tauri seems to open in browser - // causing 2 tabs to open. in m1 macs its not there. so we prevent default behavior. - event.stopImmediatePropagation(); - event.preventDefault(); + if (!event.defaultPrevented) { + window.parent.postMessage({ + handlerName: "ph-liveServer", + eventName: 'embeddedIframeHrefClick', + href: href + }, "*"); + // in intel mac desktop, tauri seems to open in browser + // causing 2 tabs to open. in m1 macs its not there. so we prevent default behavior. + event.stopImmediatePropagation(); + event.preventDefault(); + } } - }, true); + }); document.addEventListener('contextmenu', function(event) { (document.activeElement || document.body).focus(); });