ADORSYS-GIS / ADORSYS-GIS/lightbridge-opencode-toolbeit
[Ticket]: Fix Firefox Extension Crash on browser_open Action (TypeError: created is undefined)
- Vorherrschende Sprache
- TypeScript
- Sterne
- 4
- Forks
- 0
- Ø Merge
- 6 Std. 14 Min.
- Gemergte PRs (30 T.)
- 26
Beschreibung
### Type
Bug
### Summary
We need to ensure the browser extension handles tab creation safely in Firefox because calling browser_open currently returns an undefined object context when evaluating chrome.tabs.create, crashing the extension thread and preventing subsequent browser_tabs actions from finding the tab.
Expected result:
Executing a browser_open command successfully instantiates the tab in Firefox without crashing the background script thread, allowing the tab to be registered properly.
### Intent
The intention is to fix the core initialization failure on Firefox so that the extension's loopback bridge and browser automation tasks can function natively on Gecko-based browsers without manual polyfill hacks.
### Source of truth (links)
Bug caught via runtime exception breakpoints on line 102 of the unpacked extension background file corresponding to:
https://github.com/vymalo/opencode-oauth2/blob/main/apps/browser-extension/src/background/group-registry.ts#L101
Extension ID/Link on AMO:
https://addons.mozilla.org/en-US/firefox/addon/opencode-browser/
### Current Behavior
When executing a `browser_open` command, a browser tab correctly pops up, but the background thread crashes. The action logs a red failure status under the dashboard's Activity tab with the error:
`can't access property "id" of undefined`
Because it crashes during the open sequence before the tab is saved to the tracking matrix, subsequent calls to `browser_tabs` cannot locate the tab.
### Expected Behavior
When browser_open is triggered, the tab should open, its identifier should be captured safely, and it should be added to the group registry without throwing an exception. browser_tabs should subsequently be able to query and see the active tab.
### Acceptance Criteria
- [ ] Given an active loopback connection on Firefox, when a browser_open command is sent, then the tab opens and no exception is thrown in the extension background console.
- [ ] Error cases are handled safely if a tab object returns undefined.
- [ ] Existing behavior on Chromium-based browsers is not broken.
- [ ] Verification evidence is provided.
### Out of Scope
This ticket does not cover migrating the entire codebase away from the chrome.* namespace or adding wider multi-browser compatibility layers beyond fixing this specific tab-creation crash.
### Technical Context
- **Relevant File:** `apps/browser-extension/src/background/group-registry.ts` (specifically line 101/102).
- **The Crash Point:**
```typescript
const created = await chrome.tabs.create({ url: url ?? "about:blank", active: focus });
// The crash happens on the next line when evaluating created.id because 'created' is undefined.
- **Known Constraints:** The Firefox Add-on store link is currently missing from the `apps/browser-extension#install` documentation.
- **Temporary Workaround Used:** Injecting `(globalThis).chrome = browser;` at the very beginning of the compiled `background.js` wrapper bypasses the crash locally.
- **Documentation Suggestion:** The token can be manually retrieved from '%APPDATA%\opencode-browser\bridge.json', but adding this path directly to the "Guide" panel in the extension UI would greatly improve visibility for new users.
### Risks
Potential Risk: Directly modifying how the returned tab object is read might impact how tab groups are indexed on Chrome if not handled cleanly.
Mitigation: Ensure any changes use safe optional chaining or conditional null-checks that fall back gracefully on both environments.
### Test Plan
1. Load the extension unpacked in Firefox (via about:debugging).
2. Connect to the local OpenCode plugin over the loopback bridge using the token from bridge.json.
3. Trigger a browser_open action from the terminal.
4. Verify the tab opens and the Activity tab logs a successful green entry instead of the 'id of undefined' exception.
5. Run a browser_tabs query to ensure the tab is tracked.
### Verification evidence
Test output: Live Firefox DevTools breakpoint captures the failure immediately following the `chrome.tabs.create` call.
Manual verification steps: Confirmed that applying a `globalThis.chrome = browser;` mapping layer stops the crash and allows the automation loop to complete natively.
### Human accountable owner
@BasharMilesTeg
### AI Usage Declaration
Drafting the ticket, Understanding code
### Human verification completed
- [x] I understood the intent
- [x] I checked the source of truth
- [x] I reviewed all AI-generated text/code
- [x] I verified the implementation manually
- [x] I verified the tests
- [x] I checked for hallucinated assumptions
- [x] I documented remaining risks
- [x] I am the accountable owner and accept responsibility for this ticket.
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.