fix: no current window and sentry context#531
Merged
Conversation
Contributor
Greptile SummaryThis PR improves extension reliability in edge cases (no open window) and reduces Sentry noise, alongside a mechanical Key changes:
Follow-up considerations:
Confidence Score: 5/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User triggers Run / Test] --> B[chrome.windows.create\nurl: chrome://newtab]
B -->|Success| C[backgroundWindow set]
B -->|Throws e.g. No current window| D[catch block]
D --> E[chrome.tabs.create\nurl: chrome://newtab]
E -->|tab.windowId present| F[chrome.windows.get tab.windowId]
F --> C
E -->|tab.windowId falsy| G[backgroundWindow = undefined]
C --> H[sendMessage with window: backgroundWindow]
G --> H
H --> I[Workflow / Graph run starts]
subgraph Sentry beforeSend
S1[Incoming event] --> S2{message in\nSUPPRESSED_ERRORS?}
S2 -->|Yes| S3[Drop event → null]
S2 -->|No| S4[Tag extensionPage\nfrom location.href]
S4 --> S5[Forward to Sentry]
end
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/browseros-agent/apps/agent/entrypoints/app/create-graph/CreateGraph.tsx
Line: 262-278
Comment:
**Duplicate fallback logic — extract to shared utility**
The identical try/catch fallback block for creating a background window also appears verbatim in `useRunWorkflow.ts` (lines 104–120). Duplicating this logic means any future fix or change (e.g. adding error logging, adjusting the fallback URL) must be applied in two places.
Consider extracting a shared helper, e.g.:
```ts
// lib/chrome/createBackgroundWindow.ts
export async function createBackgroundWindow(): Promise<chrome.windows.Window | undefined> {
try {
return await chrome.windows.create({ url: 'chrome://newtab', focused: true, type: 'normal' })
} catch {
const tab = await chrome.tabs.create({ url: 'chrome://newtab', active: true })
if (tab.windowId) {
return chrome.windows.get(tab.windowId)
}
}
}
```
Then both call sites become a single `await createBackgroundWindow()`.
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: packages/browseros-agent/apps/agent/entrypoints/app/create-graph/CreateGraph.tsx
Line: 269-278
Comment:
**Broad catch swallows all `chrome.windows.create` failures**
The `catch` block triggers for _any_ error from `chrome.windows.create`, not only the expected `"No current window"` case. If the call fails for a different reason (e.g. an extension permission issue or an unexpected API change), the error is silently swallowed, the code falls back to `chrome.tabs.create`, and no signal reaches Sentry or the caller. This could mask legitimate bugs.
Consider narrowing the catch to only the known expected error:
```ts
} catch (err) {
const isExpected = err instanceof Error && err.message.includes('No current window')
if (!isExpected) throw err
// Fallback when no window context is available
const tab = await chrome.tabs.create({ url: 'chrome://newtab', active: true })
if (tab.windowId) {
backgroundWindow = await chrome.windows.get(tab.windowId)
}
}
```
The same applies to the equivalent block in `useRunWorkflow.ts`.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: lint issues" | Re-trigger Greptile |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces two main types of improvements: enhanced error handling and telemetry in the browser extension, and code quality improvements in the evaluation dashboard viewer. The error handling changes ensure the extension works more reliably when no window context is available and suppresses expected errors from being reported to Sentry. The dashboard viewer code is refactored for clarity and consistency by using
constinstead ofletfor variables that are not reassigned.Error handling and telemetry improvements:
CreateGraph.tsxanduseRunWorkflow.tsso that if creating a new Chrome window fails (e.g., all windows are closed), a new tab is created instead, improving robustness in edge cases. [1] [2]Code quality improvements in the evaluation dashboard viewer:
viewer.htmlto consistently useconstfor variables that are not reassigned, improving code readability and reducing potential bugs due to accidental reassignments. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]