Skip to content

Commit

Permalink
Fix invalid tab markers on startup in Firefox (#200)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-tejada authored Oct 6, 2023
1 parent bc473ef commit 0c55294
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/background/misc/tabMarkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,27 @@ async function resetTabMarkers() {
export async function initTabMarkers() {
await resetTabMarkers();

// We need to reload all "unloaded" tabs in case the user has the setting
// "Continue where you left off" enabled. If we don't those tabs will have an
// invalid tab marker. We can also not reassign the tab markers to those
// "unloaded" tabs since we can't get their title, so we don't know which tab
// marker each one has.
// We need to reload all tabs where the content script is not running in case
// the user has the setting "Continue where you left off" enabled. If we don't
// those tabs will have an invalid tab marker. We also can't reassign the tab
// markers to those tabs since we can't get their title, so we don't know
// which tab marker each one has.

if (!(await retrieve("includeTabMarkers"))) return;

const tabs = await browser.tabs.query({});

await Promise.all(
tabs
.filter((tab) => tab.status === "unloaded")
.map(async (tab) => browser.tabs.reload(tab.id))
await Promise.allSettled(
tabs.map(async (tab) => {
try {
await sendRequestToContent(
{ type: "checkContentScriptRunning" },
tab.id
);
} catch {
return browser.tabs.reload(tab.id);
}
})
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/content/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ browser.runtime.onMessage.addListener(
case "checkIfDocumentHasFocus":
return document.hasFocus();

case "checkContentScriptRunning":
return true;

case "updateNavigationToggle":
setNavigationToggle(request.enable);
await updateHintsEnabled();
Expand Down
1 change: 1 addition & 0 deletions src/typings/RequestFromBackground.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ interface SimpleContentRequest {
type:
| "restoreKeyboardReachableHints"
| "checkIfDocumentHasFocus"
| "checkContentScriptRunning"
| "onCompleted"
| "tryToFocusPage"
| "getTitleBeforeDecoration"
Expand Down

0 comments on commit 0c55294

Please sign in to comment.