Skip to content

Commit

Permalink
Cleanup needless iframe
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Nov 28, 2024
1 parent c6c64e0 commit 913637e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions webextensions/sidebar/tab-preview-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const TAB_PREVIEW_FRAME_STYLE = `
height: 100%;
left: 0;
overflow: hidden;
pointer-events: none;
/*pointer-events: none;*//* We should not keep iframe element there with unclickable state, instead we remove it on hover for safety. */
position: fixed;
right: 0;
top: 0;
Expand Down Expand Up @@ -118,7 +118,8 @@ async function prepareFrame(tabId) {
frameIdResolver = resolve;
});
browser.runtime.onMessage.addListener((message, _sender) => {
const onMessage = (message, _sender) => {
switch (message?.type) {
case 'treestyletab:ask-tab-preview-frame-id':
return promisedFrameId;
Expand All @@ -127,7 +128,14 @@ async function prepareFrame(tabId) {
frameIdResolver(message.frameId);
break;
}
});
};
browser.runtime.onMessage.addListener(onMessage);
const destroy = () => {
frame.parentNode.removeChild(frame);
browser.runtime.onMessage.removeListener(onMessage);
};
frame.addEventListener('mouseenter', destroy, { once: true });
})()`,
});
}
Expand Down

0 comments on commit 913637e

Please sign in to comment.