Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions public/_locales/ar/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "التقاط الصفحة الكاملة",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "التقاط منطقة التمرير بالكامل",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "إلغاء",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/de/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Ganze Seite erfassen",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Ganzen Scrollbereich erfassen",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Abbrechen",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Capture full page",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Capture whole scrolling area",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Cancel",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/es/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Capturar página completa",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Capturar toda el área desplazable",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Cancelar",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/es_419/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Capturar página completa",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Capturar toda el área desplazable",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Cancelar",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/fr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Capturer la page entière",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Capturer toute la zone défilante",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Annuler",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/hi/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "पूरा पेज कैप्चर करें",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "पूरा स्क्रॉल क्षेत्र कैप्चर करें",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "रद्द करें",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/id/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Tangkap halaman penuh",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Tangkap seluruh area gulir",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Batal",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/it/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Cattura pagina intera",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Cattura l'intera area scorrevole",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Annulla",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "ページ全体をキャプチャ",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "スクロール領域全体をキャプチャ",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "キャンセル",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "전체 페이지 캡처",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "스크롤 영역 전체 캡처",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "취소",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/nl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Volledige pagina vastleggen",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Volledig scrollgebied vastleggen",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Annuleren",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/pl/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Przechwyć całą stronę",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Przechwyć cały przewijany obszar",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Anuluj",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/pt_BR/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Capturar página inteira",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Capturar toda a área rolável",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Cancelar",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/ru/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Снимок всей страницы",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Снимок всей прокручиваемой области",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Отмена",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/tr/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Tam sayfayı yakala",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Tüm kaydırılabilir alanı yakala",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "İptal",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/vi/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "Chụp toàn trang",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "Chụp toàn bộ vùng cuộn",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "Hủy",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/zh_CN/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "截取整页",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "截取整个滚动区域",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "取消",
"description": "Element picker: button to cancel selection."
Expand Down
4 changes: 4 additions & 0 deletions public/_locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
"message": "擷取整個網頁",
"description": "Element picker: button to capture the full page instead."
},
"elementPickerScrollArea": {
"message": "擷取整個捲動區域",
"description": "Element picker: button shown when the selection is inside a box that scrolls; it captures the box's whole scrolling content, not just the visible part."
},
"elementPickerCancel": {
"message": "取消",
"description": "Element picker: button to cancel selection."
Expand Down
19 changes: 15 additions & 4 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,7 @@ async function captureElement(tab: chrome.tabs.Tab): Promise<void> {
cancel: chrome.i18n.getMessage('elementPickerCancel'),
larger: chrome.i18n.getMessage('elementPickerLarger'),
smaller: chrome.i18n.getMessage('elementPickerSmaller'),
scrollArea: chrome.i18n.getMessage('elementPickerScrollArea'),
},
]);
if (!selection) return;
Expand All @@ -582,6 +583,12 @@ async function captureElement(tab: chrome.tabs.Tab): Promise<void> {
await captureFullPage(tab);
return;
}
if (selection.kind === 'scroll-area') {
// The whole content of a scrolling box: the full-page pipeline, scrolling
// the box the picker tagged and cropping to it.
await captureFullPage(tab, { mode: 'element', scrollTarget: true });
return;
}

// Element rectangles are viewport-relative, independent of inner scroll panels.
// Read fresh dimensions: the user may resize or zoom while choosing.
Expand Down Expand Up @@ -630,9 +637,13 @@ async function captureElement(tab: chrome.tabs.Tab): Promise<void> {
}
}

async function captureFullPage(tab: chrome.tabs.Tab): Promise<void> {
async function captureFullPage(
tab: chrome.tabs.Tab,
{ mode = 'full-page', scrollTarget = false }: { mode?: CaptureMode; scrollTarget?: boolean } = {},
): Promise<void> {
const tabId = tab.id as number;
const metrics = await execInTab(tabId, getMetrics, [true]);
// scrollTarget: scroll the box the element picker tagged instead of the page.
const metrics = await execInTab(tabId, getMetrics, [true, scrollTarget]);
if (metrics.viewportHeight <= 0 || metrics.scrollHeight <= 0) {
await runInTab(tabId, restoreCapture, []);
broadcast({
Expand Down Expand Up @@ -704,7 +715,7 @@ async function captureFullPage(tab: chrome.tabs.Tab): Promise<void> {
dataUrl,
width: canvasWidth,
height: part.height,
mode: 'full-page',
mode,
title: tab.title ?? '',
url: tab.url ?? '',
capturedAt: Date.now(),
Expand Down Expand Up @@ -759,7 +770,7 @@ async function captureFullPage(tab: chrome.tabs.Tab): Promise<void> {
firstPartUrl,
canvasWidth,
canvasHeight,
'full-page',
mode,
tab.title ?? '',
tab.url ?? '',
windowId,
Expand Down
38 changes: 35 additions & 3 deletions src/content/element-select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ export interface ElementPickerLabels {
cancel: string;
larger: string;
smaller: string;
/** Button that captures the whole content of a scrolling box. */
scrollArea: string;
}

export type ElementSelection = { kind: 'element'; rect: PageRect } | { kind: 'full-page' };
/**
* What the picker chose. `scroll-area` means the whole content of a scrolling
* box: the picker tags that box `data-oss-scroll-target`, and the full-page
* pipeline scrolls it instead of the page (getMetrics in scroll-capture.ts).
*/
export type ElementSelection =
{ kind: 'element'; rect: PageRect } | { kind: 'full-page' } | { kind: 'scroll-area' };

/** Injected with executeScript: all runtime helpers must stay inside this function. */
export function selectElement(labels: ElementPickerLabels): Promise<ElementSelection | null> {
return new Promise((resolve) => {
const doc = document;
const marker = 'data-openscreenshot-element-picker';
const scrollTag = 'data-oss-scroll-target';
// A tag left by a capture that never ran must not steer this one.
for (const el of doc.querySelectorAll(`[${scrollTag}]`)) el.removeAttribute(scrollTag);
// A DOM event also works across separately serialized invocations.
doc.querySelector(`[${marker}]`)?.dispatchEvent(new Event('openscreenshot-cancel'));
let active = doc.activeElement;
Expand Down Expand Up @@ -105,6 +116,8 @@ export function selectElement(labels: ElementPickerLabels): Promise<ElementSelec
const smaller = button(labels.smaller);
const capture = button(labels.capture);
capture.className = 'primary';
const scrollArea = button(labels.scrollArea);
scrollArea.hidden = true;
const fullPage = button(labels.fullPage);
const cancel = button(labels.cancel);
bar.append(title, instructions, status, actions);
Expand Down Expand Up @@ -247,6 +260,18 @@ export function selectElement(labels: ElementPickerLabels): Promise<ElementSelec
}
return true;
};
// The selection, or the nearest box around it, that scrolls vertically and
// sits fully on screen: its whole content can be captured by scrolling it.
const scrollBox = (from: Element | null): HTMLElement | null => {
for (let el = from; el && el !== doc.body && el !== doc.documentElement; el = parent(el)) {
if (!(el instanceof HTMLElement) || !usable(el)) continue;
const css = getComputedStyle(el);
if (!/^(auto|scroll)$/.test(css.overflowY) || el.scrollHeight <= el.clientHeight + 1)
continue;
return fullyVisible(el, el.getBoundingClientRect()) ? el : null;
}
return null;
};
const render = () => {
if (current && !usable(current)) {
current = null;
Expand All @@ -267,6 +292,7 @@ export function selectElement(labels: ElementPickerLabels): Promise<ElementSelec
}
capture.disabled = !visible;
fullPage.hidden = !current || visible;
scrollArea.hidden = !scrollBox(current);
larger.disabled = !ancestor(current);
smaller.disabled = !history.some(usable) && !(smallerTarget && usable(smallerTarget));
const text =
Expand Down Expand Up @@ -391,7 +417,13 @@ export function selectElement(labels: ElementPickerLabels): Promise<ElementSelec
if (target.disabled || target.hidden) return;
if (target === cancel) finish(null);
else if (target === capture) confirm();
else if (target === fullPage) {
else if (target === scrollArea) {
const box = scrollBox(current);
if (box) {
box.setAttribute(scrollTag, '');
finish({ kind: 'scroll-area' });
}
} else if (target === fullPage) {
render();
if (!fullPage.hidden) finish({ kind: 'full-page' });
} else if (target === larger) grow();
Expand Down Expand Up @@ -442,7 +474,7 @@ export function selectElement(labels: ElementPickerLabels): Promise<ElementSelec
event.stopImmediatePropagation();
if (event.key === 'Tab') {
event.preventDefault();
const available = [larger, smaller, capture, fullPage, cancel].filter(
const available = [larger, smaller, capture, scrollArea, fullPage, cancel].filter(
(el) => !el.disabled && !el.hidden,
);
const index = available.indexOf(shadow.activeElement as HTMLButtonElement);
Expand Down
12 changes: 9 additions & 3 deletions src/content/scroll-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ export function getWindowViewport() {
* `data-oss-expanded`, so the capture holds them whole. {@link restoreCapture}
* puts them back.
*/
export function getMetrics(excludeScrollbars = false): Metrics {
export function getMetrics(excludeScrollbars = false, scrollTarget = false): Metrics {
const de = document.documentElement;
// The element picker's "Capture whole scrolling area" tags the box to scroll.
// Only that capture uses the tag; any other capture clears a stale one.
const tagged = document.querySelector<HTMLElement>('[data-oss-scroll-target]');
if (tagged && !scrollTarget) tagged.removeAttribute('data-oss-scroll-target');
const forced = scrollTarget ? tagged : null;
const dpr = window.devicePixelRatio || 1;
// client dimensions exclude classic scrollbar gutters without reflowing
// the page. Overlay scrollbars are made transparent during preparation.
Expand All @@ -63,9 +68,9 @@ export function getMetrics(excludeScrollbars = false): Metrics {
// When the document can grow, a panel that overflows by less than half a
// viewport is expanded in place instead, which keeps the page around it.
// ponytail: linear DOM scan, fine for a one-shot capture; index by overflow if it ever matters.
let scroller: HTMLElement | null = null;
let scroller: HTMLElement | null = forced;
let bestOverflow = Math.max(documentScrolls ? vh * 0.5 : 4, de.scrollHeight - vh);
for (const el of document.querySelectorAll<HTMLElement>('*')) {
for (const el of forced ? [] : document.querySelectorAll<HTMLElement>('*')) {
const cs = getComputedStyle(el);
if (cs.overflowY !== 'auto' && cs.overflowY !== 'scroll') continue;
const overflow = el.scrollHeight - el.clientHeight;
Expand Down Expand Up @@ -324,6 +329,7 @@ export function restoreCapture(): void {
}
const scroller = document.querySelector<HTMLElement>('[data-oss-scroller="1"]');
if (scroller) delete scroller.dataset.ossScroller;
document.querySelector('[data-oss-scroll-target]')?.removeAttribute('data-oss-scroll-target');
}

/**
Expand Down
Loading