Skip to content

Commit

Permalink
Handle the lack of chrome.windows gracefully.
Browse files Browse the repository at this point in the history
Currently, antitracking crashes on startup on Android.
  • Loading branch information
philipp-classen committed Dec 9, 2024
1 parent fbe924a commit c3cf364
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions reporting/src/request/page-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ export default class PageStore {
chrome.webNavigation.onBeforeNavigate.addListener(this.#onBeforeNavigate);
chrome.webNavigation.onCommitted.addListener(this.#onNavigationCommitted);
chrome.webNavigation.onCompleted.addListener(this.#onNavigationCompleted);
chrome.windows.onFocusChanged?.addListener(this.#onWindowFocusChanged);

// Note: not available on Firefox Android
chrome.windows?.onFocusChanged?.addListener(this.#onWindowFocusChanged);

// popupate initially open tabs
(await chrome.tabs.query({})).forEach((tab) => this.#onTabCreated(tab));
Expand All @@ -103,7 +105,7 @@ export default class PageStore {
chrome.webNavigation.onCompleted.removeListener(
this.#onNavigationCompleted,
);
chrome.windows.onFocusChanged?.removeListener(this.#onWindowFocusChanged);
chrome.windows?.onFocusChanged?.removeListener(this.#onWindowFocusChanged);
}

checkIfEmpty() {
Expand Down Expand Up @@ -182,6 +184,7 @@ export default class PageStore {
}
};

// Note: not available on Firefox Android
#onWindowFocusChanged = async (focusedWindowId) => {
const activeTabs = await chrome.tabs.query({ active: true });
for (const { id, windowId } of activeTabs) {
Expand Down

0 comments on commit c3cf364

Please sign in to comment.