this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fixed bug caused by browser extension idle/sleep.

+62 -37
+3 -1
CHANGELOG.md
··· 9 9 10 10 ## [Unreleased] 11 11 12 + - Small fix for a bug introduced in `1.4.0` that occurs when the browser puts idle extensions to sleep 13 + 12 14 ## [1.4.0] 13 15 14 16 ### Changed 15 17 16 18 - Migrate/refactor everything from `content.js` into a self-contained `background.js` 17 19 - Swap `activeTab` permission for `tabs` so that we can drop the `<all_urls>` permission 18 - - Remove permissions for "management" as it is not needed 20 + - Remove permissions for `management` as it is not needed 19 21 - Migrate Firefox to Manifest v3 (but this means the minimum FF version is now 109) 20 22 - Input validation for domains and DIDs (security enhancement) 21 23 - Replace `staging.bsky.app` with `bsky.app`
+59 -36
background.js
··· 103 103 // The cache is cleared when the tab is closed 104 104 const didCache = new Map() 105 105 106 - function performAction(tab) { 107 - storage.get("privacyConsentAccepted", ({ privacyConsentAccepted }) => { 108 - if (privacyConsentAccepted) { 109 - const domain = getDomainName(tab.url) 110 - if (isValidDomain(domain)) { 111 - // Check if we have cached DID for this tab and domain 112 - const cachedDID = didCache.get(`${tab.id}:${domain}`) 113 - if (cachedDID !== undefined) { 114 - // If we have a cached DID or a cached "not found" state, use it 115 - if (cachedDID !== null) { 116 - setDID(tab, cachedDID) 117 - } else { 118 - setIcon(tab.id, "logo48_gray.png") 119 - tabsWithDID.delete(tab.id) 120 - } 121 - } else { 122 - // If not, proceed with the checks 123 - checkForDIDDNS(domain).then((domainDID) => { 124 - if (domainDID) { 125 - setDID(tab, domainDID) 126 - didCache.set(`${tab.id}:${domain}`, domainDID) 106 + async function performAction(tab) { 107 + return new Promise((resolve, reject) => { 108 + storage.get( 109 + "privacyConsentAccepted", 110 + async ({ privacyConsentAccepted }) => { 111 + if (privacyConsentAccepted) { 112 + const domain = getDomainName(tab.url) 113 + if (isValidDomain(domain)) { 114 + // Check if we have cached DID for this tab and domain 115 + const cachedDID = didCache.get(`${tab.id}:${domain}`) 116 + if (cachedDID !== undefined) { 117 + // If we have a cached DID or a cached "not found" state, use it 118 + if (cachedDID !== null) { 119 + setDID(tab, cachedDID) 120 + } else { 121 + setIcon(tab.id, "logo48_gray.png") 122 + tabsWithDID.delete(tab.id) 123 + } 124 + resolve() 127 125 } else { 128 - checkForDIDHTTPS(domain).then((httpsDID) => { 126 + // If not, proceed with the checks 127 + const domainDID = await checkForDIDDNS(domain) 128 + if (domainDID) { 129 + setDID(tab, domainDID) 130 + didCache.set(`${tab.id}:${domain}`, domainDID) 131 + resolve() 132 + } else { 133 + const httpsDID = await checkForDIDHTTPS(domain) 129 134 if (httpsDID) { 130 135 setDID(tab, httpsDID) 131 136 didCache.set(`${tab.id}:${domain}`, httpsDID) ··· 135 140 // Cache the "not found" state 136 141 didCache.set(`${tab.id}:${domain}`, null) 137 142 } 138 - }) 143 + resolve() 144 + } 139 145 } 140 - }) 146 + } else { 147 + reject(new Error("Invalid domain")) 148 + } 149 + } else { 150 + reject(new Error("Privacy consent not accepted")) 141 151 } 142 152 } 143 - } 153 + ) 144 154 }) 145 155 } 146 156 ··· 193 203 }) 194 204 }) 195 205 196 - // Open the consent page if it hasn't been accepted and the user clicks on the extension icon 197 - action.onClicked.addListener(() => { 206 + // When the extension icon is clicked 207 + action.onClicked.addListener((tab) => { 208 + // Get privacyConsentAccepted from storage 198 209 storage.get("privacyConsentAccepted", ({ privacyConsentAccepted }) => { 210 + // If privacyConsentAccepted is undefined or false, open the consent page 199 211 if ( 200 212 typeof privacyConsentAccepted === "undefined" || 201 213 !privacyConsentAccepted 202 214 ) { 203 215 tabs.create({ url: "privacy_consent.html" }) 216 + } else { 217 + // If there is a DID for this tab, open the profile page 218 + const did = tabsWithDID.get(tab.id) 219 + if (did) { 220 + const newUrl = `${bskyAppUrl}/profile/${did}` 221 + tabs.create({ url: newUrl }) 222 + } else { 223 + // If there is no DID for this tab in cache, run performAction 224 + const domain = getDomainName(tab.url) 225 + if (isValidDomain(domain)) { 226 + performAction(tab).then(() => { 227 + // If performAction returned a DID, open the profile page 228 + const didAfterPerformingAction = tabsWithDID.get(tab.id) 229 + if (didAfterPerformingAction) { 230 + const newUrl = `${bskyAppUrl}/profile/${didAfterPerformingAction}` 231 + tabs.create({ url: newUrl }) 232 + } 233 + }) 234 + } 235 + } 204 236 } 205 237 }) 206 238 }) 207 - 208 - // When the extension icon is clicked, open the profile page if there's a DID 209 - action.onClicked.addListener((tab) => { 210 - const did = tabsWithDID.get(tab.id) 211 - if (did) { 212 - const newUrl = `${bskyAppUrl}/profile/${did}` 213 - tabs.create({ url: newUrl }) 214 - } 215 - })