Skip to content

Commit f57f21d

Browse files
committed
fix(browser): probe only the main frame for Google Docs selections
All-frame injection rejects wholesale when one frame is inaccessible and returns child frames in nondeterministic order, so the probe now reads the main frame only. Child-frame selections still share correctly through the context menu's click-time selectionText; toolbar/shortcut entry sends the full page for that case (named tradeoff in the code comment).
1 parent 7714e95 commit f57f21d

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

‎extensions/browser/chrome-extension/background.js‎

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,19 +524,16 @@ async function capturePageShare(tab) {
524524
}
525525

526526
async function captureDomSelection(tabId) {
527+
// Main frame only, deliberately: all-frame probes reject wholesale on one
528+
// inaccessible frame and return child frames in nondeterministic order.
529+
// Child-frame selections are served by the context menu's selectionText;
530+
// toolbar/shortcut on a child-frame selection sends the full page instead.
527531
try {
528-
// allFrames: a highlighted passage can live in a same-origin child frame
529-
// the main-frame probe cannot see; missing it would export the whole doc.
530-
const injections = await chrome.scripting.executeScript({
531-
target: { tabId, allFrames: true },
532+
const [injection] = await chrome.scripting.executeScript({
533+
target: { tabId },
532534
func: () => window.getSelection()?.toString().trim() ?? "",
533535
});
534-
for (const injection of injections ?? []) {
535-
if (typeof injection?.result === "string" && injection.result) {
536-
return injection.result;
537-
}
538-
}
539-
return "";
536+
return typeof injection?.result === "string" ? injection.result : "";
540537
} catch {
541538
return "";
542539
}

0 commit comments

Comments
 (0)