From 28eb3f2aaed40698f8d53509690233348862d206 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 9 Oct 2020 22:07:26 +0200 Subject: [PATCH] clip screenshot crops correctly when HIDPI display is used --- .idea/vcs.xml | 1 - background.js | 9 +++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.idea/vcs.xml b/.idea/vcs.xml index fdf1fc87c..94a25f7f4 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,7 +1,6 @@ - \ No newline at end of file diff --git a/background.js b/background.js index 034a2a8e0..06b8c2213 100644 --- a/background.js +++ b/background.js @@ -36,7 +36,12 @@ function cropImage(newArea, dataUrl) { async function takeScreenshot(cropRect) { const activeTab = await getActiveTab(); - const zoom = await browser.tabs.getZoom(activeTab.id); + const isFirefox = typeof InstallTrigger !== 'undefined'; + + // Chrome/blink do not incorporate automatically the devicePixelRatio so we need to do it manually + const zoom = await browser.tabs.getZoom(activeTab.id) + * (isFirefox ? 1 : window.devicePixelRatio); + const newArea = Object.assign({}, cropRect); newArea.x *= zoom; newArea.y *= zoom; @@ -332,4 +337,4 @@ browser.runtime.onMessage.addListener(async request => { else if (request.name === 'send-trilium-search-status') { triliumServerFacade.sendTriliumSearchStatusToPopup(); } -}); \ No newline at end of file +});