Skip to content

Commit

Permalink
Add restriction on tab opening to the current active tab
Browse files Browse the repository at this point in the history
In the existing extension, any tab initiating a PrivateToken request for
a trusted issuer is going to trigger the associated attester tab
opening. This might interrupt the user flow.
This commit introduces an improvement to only allow the current active
tab to open a new tab upon a PrivateToken request.
  • Loading branch information
thibmeu committed Jan 11, 2024
1 parent 4d1ffed commit 3139f4f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ export const headerToToken = async (
// API expects interactive Challenge at /challenge
attesterURI = `${attesterURI}/challenge`;

// To minimize the number of tabs opened, we check if the requesting tab is the active tab
const activeTab: number | undefined = await new Promise((resolve) =>
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) =>
resolve(tabs[0].id),
),
);
if (activeTab !== tabId) {
logger.debug('Not openning a new tab due to requesting tab not being active');
return undefined;
}
const tab: chrome.tabs.Tab = await new Promise((resolve) =>
chrome.tabs.create({ url: attesterURI }, resolve),
);
Expand Down

0 comments on commit 3139f4f

Please sign in to comment.