Skip to content

Commit

Permalink
fix: use better autoconnect interface
Browse files Browse the repository at this point in the history
  • Loading branch information
janek26 committed Oct 26, 2023
1 parent 0380b7b commit 9780841
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/shared/chrome.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ type AllowCleanUpFunction = void | (() => void);
* @param onConnect - callback when connected
*/
export async function autoConnect(
browser: typeof chrome,
createPort: () => chrome.runtime.Port,
onConnect: (port: chrome.runtime.Port) => AllowCleanUpFunction,
) {
const port = await retry(
() => browser.runtime.connect(),
createPort,
3, // 3 retries plus the initial try, so 4 total tries
(retry) => wait(retry * 100), // 100ms, 200ms, 300ms, max total wait 600ms
);
Expand All @@ -22,6 +22,6 @@ export async function autoConnect(
port.onDisconnect.addListener(() => {
cleanUp?.();
console.log('Port disconnected, reconnecting...');
void autoConnect(browser, onConnect);
void autoConnect(createPort, onConnect);
});
}

0 comments on commit 9780841

Please sign in to comment.