Skip to content

Commit

Permalink
target updated tab init message to document id
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Jun 19, 2024
1 parent 28f9139 commit f02645d
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions apps/extension/src/listeners/tabs-updated-prax-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@ import { PraxConnection } from '../message/prax';

// trigger injected-connection-port to init when a known page is loaded.
chrome.tabs.onUpdated.addListener(
(tabId, { status, discarded }, { url }) =>
(tabId, { status, discarded, url: changeInfoUrl }, { url: tabUrl }) => {
console.log({ tabUrl, changeInfoUrl });
const url = changeInfoUrl ?? tabUrl;
const documentUrls = [tabUrl, changeInfoUrl].filter(id => id) as string[];
const getContext = chrome.runtime
.getContexts({ tabIds: [tabId], documentUrls })
.then(contexts => contexts.filter(({ frameId }) => !frameId)[0]);
void (async () => {
const documentId = (await getContext)?.documentId;
if (
documentId &&
status === 'complete' &&
!discarded &&
url?.startsWith('https://') &&
(await originAlreadyApproved(url))
)
// How can we scope this to documentId?
void chrome.tabs.sendMessage(tabId, PraxConnection.Init);
})(),
void chrome.runtime.sendMessage(PraxConnection.Init, { tabId, documentId });
})();
},
);

0 comments on commit f02645d

Please sign in to comment.