-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#6624: Exclude discarded tabs in broadcasts and other "all tabs" actions #6626
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #6626 +/- ##
==========================================
+ Coverage 70.15% 70.19% +0.03%
==========================================
Files 1179 1178 -1
Lines 36654 36652 -2
Branches 6899 6899
==========================================
+ Hits 25715 25727 +12
+ Misses 10939 10925 -14
☔ View full report in Codecov by Sentry. |
@@ -436,7 +437,7 @@ export async function pong(): Promise<{ timestamp: number }> { | |||
*/ | |||
export async function collectPerformanceDiagnostics(): Promise<Diagnostics> { | |||
const timestamp = Date.now(); | |||
const allTabs = await browser.tabs.query({}); | |||
const allTabs = await getTabsWithAccess(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now excludes discarded tabs and other tabs where PB does not run. I think it wouldn't make sense to track those. Can revert if needed
export async function getTabsWithAccess(): Promise<TabId[]> { | ||
const tabs = await browser.tabs.query({ | ||
url: ["https://*/*", "http://*/*"], | ||
discarded: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the core of the change:
- only query the specific protocols we're looking for
- exclude
discarded
tabs
const tabs = await getTabsWithAccess(); | ||
|
||
if (tabs.length > 20) { | ||
console.warn("forEachTab called on more than 20"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Second core part:
- Log to console if there are a lot of tabs.
Alternatively:
- replace this with
reportEvent
?
TCallback extends (target: { tabId: number }) => Promisable<unknown> | ||
>( | ||
callback: TCallback, | ||
options?: { exclude: number } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
forEachTab
now lets you optionally exclude a specific tab. I think this is useful in any instance where the action originates in a tab.
59d1db9
to
4a103ed
Compare
@@ -1,39 +0,0 @@ | |||
/** @file It's possible that some of these tabs might lose the permission in the meantime, we can't track that exactly */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"activeTab" referred to some logic that was dropped a few months ago. I moved these functions to extensionUtils
// The origin should be set to the window.location.protocol + '//' + | ||
// window.location.host of the top-most page, if your application is | ||
// running in an iframe. | ||
return url.protocol + "//" + url.host; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up here looking for tabs.query()
usage
The comments in this file seem copy-pasted and out of place (it mentions "in this PR", what PR?). I dropped some.
async ({ tabId }) => | ||
safelyRunBrick({ tabId, frameId: TOP_LEVEL_FRAME_ID }, subRequest), | ||
{ | ||
exclude: sourceTabId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replacing asyncForEach
with the more specific forEachTab
here allowed for a slight refactoring, thanks to the included Promise.allSettled
if (rejected.length > 0) { | ||
console.warn(`Broadcast rejected for ${rejected.length} tabs`, { | ||
rejected, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the possible reasons for rejected tabs? Stale or closed tabs? Should we log this to Rollbar as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are the possible reasons for rejected tabs?
- Non-scriptable tabs. I can actually include a filter for this
- Existing tabs are not connectable after an install or extension update #6548
- any other content script failure or timeout
- user navigates away while the brick runs
Stale or closed tabs?
Discarded tabs are already excluded.
There's a possible race condition if the user closes a tab between line 165 and line 166 😅 but I reckon it's rare.
Should we log this to Rollbar as well?
I think this generally classifies as user/business error. We don't log errors that are due to unconnectable tabs.
if (rejected.length > 0) { | ||
console.warn(`Broadcast rejected for ${rejected.length} frame`, { | ||
rejected, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, except that frames are more likely to come into existence and disappear. Still classifies as a non-reportable error.
Adding @BLoe as reviewer because he will be helping out with performance issues |
No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack. Do not edit this comment manually. |
5ad0e78
to
8d8498a
Compare
What does this PR do?
It's ready for review.
I'll want to test this before merging thoughDoneChecklist
src/tsconfig.strictNullChecks.json
(if possible)