Skip to content

Commit

Permalink
fix(chrome-extension): restore state on tab close
Browse files Browse the repository at this point in the history
  • Loading branch information
meskill committed Sep 18, 2022
1 parent 4b2867d commit e018168
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion chrome-extension/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ export class MysticLightApi {

const endpoint = `${this.serverUrl}/mystic_light`;

this.client = new GraphQLClient(endpoint);
this.client = new GraphQLClient(endpoint, {
fetch: (requestInfo: RequestInfo | URL, init?: RequestInit) => {
return fetch(requestInfo, {
...init,
keepalive: true,
});
},
});
}

async healthz() {
Expand Down
7 changes: 7 additions & 0 deletions chrome-extension/src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ window.addEventListener('resize', async () => {
}
});

// restore state if any on browser tab or window close
document.addEventListener('visibilitychange', () => {
if (document.visibilityState === 'hidden') {
api?.revertPrevStates();
}
});

chrome.runtime.onMessage.addListener((request: ExtensionMessageShowAlert['request']) => {
if (request.type === 'showAlert') {
alert(request.message);
Expand Down

0 comments on commit e018168

Please sign in to comment.