From c5139110e8568524ecdeb708790f56c8877a5e2b Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 14 Aug 2025 14:19:21 -0700 Subject: [PATCH 1/2] Fix Frames --- src/js/exports.js | 30 ++++++++++++++++++++++++++---- src/js/links.js | 22 ++++++++++++++++++---- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/src/js/exports.js b/src/js/exports.js index 8e594b9..17c4150 100644 --- a/src/js/exports.js +++ b/src/js/exports.js @@ -54,14 +54,36 @@ export async function injectTab({ return } - // Inject extract.js which listens for messages + // // Inject extract.js which listens for messages + // for (const tab of tabIds) { + // console.debug(`injecting tab.id: ${tab}`) + // await chrome.scripting.executeScript({ + // target: { tabId: tab, allFrames: true }, + // files: ['/js/extract.js'], + // }) + // } + + // TODO: The only way to support frames without extra permissions is to either: + // Extract the frame data at injection time, or + // Extract the links at injection time (requires refactoring)... + const tabs = [] for (const tab of tabIds) { console.debug(`injecting tab.id: ${tab}`) - await chrome.scripting.executeScript({ - target: { tabId: tab }, + const results = await chrome.scripting.executeScript({ + target: { tabId: tab, allFrames: true }, files: ['/js/extract.js'], }) + console.debug('results:', results) + const frameIds = results.map((item) => item.frameId) + console.debug('frameIds:', frameIds) + frameIds.shift() + if (frameIds.length) { + tabs.push(`${tab}-${frameIds.join('-')}`) + } else { + tabs.push(tab) + } } + console.debug('tabs:', tabs) // Create URL to links.html if open if (!open) { @@ -70,7 +92,7 @@ export async function injectTab({ } const url = new URL(chrome.runtime.getURL('/html/links.html')) // Set URL searchParams - url.searchParams.set('tabs', tabIds.join(',')) + url.searchParams.set('tabs', tabs.join(',')) if (filter) { url.searchParams.set('filter', filter) } diff --git a/src/js/links.js b/src/js/links.js index 95b22fb..d1f85c0 100644 --- a/src/js/links.js +++ b/src/js/links.js @@ -161,18 +161,32 @@ async function initLinks() { try { const tabIds = urlParams.get('tabs') const tabs = tabIds?.split(',') - const selection = urlParams.has('selection') + const action = urlParams.has('selection') ? 'selection' : 'all' + // TODO: See the TODO in export.js for injectTab() + // This is a temporary fix being tested... const allLinks = [] if (tabs?.length) { console.debug('tabs:', tabs) - for (const tabId of tabs) { - const action = selection ? 'selection' : 'all' + for (const tab of tabs) { + const frames = tab.split('-') + const tabId = frames.shift() + console.debug('tabId:', tabId) const links = await chrome.tabs.sendMessage( parseInt(tabId), - action + action, + { frameId: 0 } ) allLinks.push(...links) + for (const frame of frames) { + console.debug('frame:', frame) + const links = await chrome.tabs.sendMessage( + parseInt(tabId), + action, + { frameId: parseInt(frame) } + ) + allLinks.push(...links) + } } } else { const { links } = await chrome.storage.local.get(['links']) From e9050a52f27728008a721e1bdb543d315232d1df Mon Sep 17 00:00:00 2001 From: Shane <6071159+smashedr@users.noreply.github.com> Date: Thu, 14 Aug 2025 15:40:37 -0700 Subject: [PATCH 2/2] Add Loading Spinner --- src/html/links.html | 6 +++++- src/js/links.js | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/html/links.html b/src/html/links.html index 041cc4d..c3b3e02 100644 --- a/src/html/links.html +++ b/src/html/links.html @@ -15,6 +15,11 @@
+