Skip to content

Commit

Permalink
patch: fixes bug blocking request popup from closing when session is …
Browse files Browse the repository at this point in the history
…complete (v0.23.9)
  • Loading branch information
this-oliver committed Sep 5, 2023
1 parent eee5b21 commit ae73180
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ssasy-auth/extension",
"nickname": "ssasy",
"version": "0.23.8",
"version": "0.23.9",
"license": "MIT",
"description": "A browser extension that offers a secure and usable alternative to passwords and federated identity providers.",
"repository": "this-oliver/ssasy-ext",
Expand Down
41 changes: 28 additions & 13 deletions src/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,32 @@ if (import.meta.hot) {
import('./contentScriptHMR');
}

/**
* Session object
*/
export interface Session {
request: PublicKeyRequest | ChallengeRequest;
popupPage: Windows.Window | Tabs.Tab;
}

let currentRequestTab: number = -1;
/**
* Current request tab id
*/
let requestTab: number = -1;

/**
* Close current request tab and reset `requestTab` to `-1`
*/
function _closeRequestTab(): void {
// close popup window if it is open
if (requestTab !== -1) {
PopupPage.close({ id: requestTab });
}

// reset current request tab
requestTab = -1;

}

/**
* Listen for current tab requests from content scripts
Expand All @@ -38,10 +58,8 @@ onMessage('close-request-tab', ({ data }) => {
Logger.error(error.error, null, 'background');
}

// close popup window
if (currentRequestTab !== -1) {
PopupPage.close({ id: currentRequestTab });
}
// close current request tab
_closeRequestTab();
})

/**
Expand All @@ -64,8 +82,8 @@ onMessage(MessageType.REQUEST_PUBLIC_KEY, async ({ data }) => {
popupPage: await PopupPage.open({ queryString: query })
}

currentRequestTab = session.popupPage.id || 0;
Logger.info('currentRequestTab set to ', currentRequestTab, 'background');
requestTab = session.popupPage.id || 0;
Logger.info('requestTab set to ', requestTab, 'background');

// wait for response from popup window
return new Promise((resolve) => {
Expand Down Expand Up @@ -95,9 +113,6 @@ onMessage(MessageType.REQUEST_PUBLIC_KEY, async ({ data }) => {
key: msg.key
};

// reset current request tab
currentRequestTab = -1;

// respond to content script
return resolve(response);
}
Expand All @@ -124,14 +139,14 @@ onMessage(MessageType.REQUEST_SOLUTION, async ({ data }) => {
return new Promise((resolve) => {
// broadcast undefined response, if the messageSession is still active and popup window is closed
browser.windows.onRemoved.addListener(async (windowId) => {
if (currentRequestTab === windowId) {
if (requestTab === windowId) {
const response: ChallengeResponse = {
type: MessageType.RESPONSE_SOLUTION,
solution: null
};

// reset current request tab
currentRequestTab = -1;
// close current request tab
_closeRequestTab();

return resolve(response);
}
Expand Down

0 comments on commit ae73180

Please sign in to comment.