From a42554fe1df2b32d197ff59c77fc982b8062f462 Mon Sep 17 00:00:00 2001 From: Ronan Jouchet Date: Thu, 29 Sep 2016 14:10:28 -0400 Subject: [PATCH] Fix context menu actions broken on elements containing nested markup Test case: open nativefier on ```html Test Google
Google, in span ``` * **Expected**: both links open in default browser * **Actual under nativefier 7.0.1**: Nothing happens when clicking the second link in which the `` contains a `` --- app/src/static/preload.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/src/static/preload.js b/app/src/static/preload.js index 27e704b..9cacbf6 100644 --- a/app/src/static/preload.js +++ b/app/src/static/preload.js @@ -17,6 +17,12 @@ document.addEventListener('DOMContentLoaded', () => { window.addEventListener('contextmenu', event => { event.preventDefault(); const targetElement = event.srcElement; + + // the clicked element is the deepest in the DOM, and may not be the bearing the href + // for example, Google + while (!targetElement.href && targetElement.parentElement) { + targetElement = targetElement.parentElement; + } const targetHref = targetElement.href; if (!targetHref) {