Skip to content

Commit

Permalink
fix: internal pages init
Browse files Browse the repository at this point in the history
- increased deadline for waiting init data
- added new injection case on tab update

(resolves #1975)
  • Loading branch information
mbnuqw committed Jan 22, 2025
1 parent 6781603 commit 4977b6f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/injections/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ function waitInitData(): Promise<void> {
return new Promise((ok, err) => {
if (window.sideberyInitData) return ok()
window.onSideberyInitDataReady = ok
setTimeout(() => err('GroupPage: No initial data (sideberyInitData)'), 2000)
setTimeout(() => {
if (window.sideberyInitData) return
err('GroupPage: No initial data (sideberyInitData)')
}, 60_000)
})
}

Expand Down
5 changes: 4 additions & 1 deletion src/injections/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ function waitInitData(): Promise<void> {
return new Promise((ok, err) => {
if (window.sideberyInitData) return ok()
window.onSideberyInitDataReady = ok
setTimeout(() => err('UrlPage: No initial data (sideberyInitData)'), 2000)
setTimeout(() => {
if (window.sideberyInitData) return
err('UrlPage: No initial data (sideberyInitData)')
}, 60_000)
})
}

Expand Down
20 changes: 16 additions & 4 deletions src/services/tabs.bg.actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function onTabUpdated(tabId: ID, change: browser.tabs.ChangeInfo): void {
return
}

let groupScriptInjectionIsNeeded = false
const tab = Tabs.byId[tabId]
if (!tab) return

Expand All @@ -189,14 +190,20 @@ function onTabUpdated(tabId: ID, change: browser.tabs.ChangeInfo): void {
}

if (change.status !== undefined) {
if (change.status === 'complete' && tab.url[0] !== 'a' && !tab.internal) {
reloadTabFaviconDebounced(tab)
if (change.status === 'complete') {
if (tab.url[0] !== 'a' && !tab.internal) {
reloadTabFaviconDebounced(tab)
}
// Check if injection of group-page script is needed
if (tab.internal && !change.title && tab.title === GROUP_INITIAL_TITLE) {
groupScriptInjectionIsNeeded = true
}
}
}

// Inject group page script if internal page has initial title
// Check if injection of group-page script is needed
if (change.title && tab.internal && !tab.discarded && change.title === GROUP_INITIAL_TITLE) {
injectGroupPageScript(tab.windowId, tabId)
groupScriptInjectionIsNeeded = true
}

if (
Expand All @@ -207,6 +214,11 @@ function onTabUpdated(tabId: ID, change: browser.tabs.ChangeInfo): void {
Favicons.saveFavicon(tab.url, change.favIconUrl)
}

// Inject group page script if internal page has initial title
if (groupScriptInjectionIsNeeded) {
injectGroupPageScript(tab.windowId, tabId)
}

Object.assign(tab, change)

if (WebReq.containersProxies[tab.cookieStoreId]) {
Expand Down

0 comments on commit 4977b6f

Please sign in to comment.