Skip to content

Compatibility changes for gekko and blink based browsers #181

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Saksham-Sirohi
Copy link
Contributor

@Saksham-Sirohi Saksham-Sirohi commented Jul 5, 2025

Solves Chore #120 #135

Summary by Sourcery

Enable cross-browser compatibility by introducing browser-polyfill, replacing chrome.* calls with async browser.* methods, updating scripts and manifest for Firefox support, and adding the polyfill dependency

New Features:

  • Support both Chrome (Blink) and Firefox (Gecko) via a browser API polyfill
  • Unified async storage and runtime functions replacing callback-based chrome.storage calls

Enhancements:

  • Refactor all chrome.* API usages to browser.* and async/await patterns across content, main and popup scripts
  • Inject browser-polyfill.js in content and popup and update manifest to include it

Build:

  • Add browser-polyfill dependency to package.json

Copy link
Contributor

sourcery-ai bot commented Jul 5, 2025

Reviewer's Guide

This PR introduces a cross-browser storage abstraction using a browser/polyfill approach, refactors all chrome.* callbacks into async/await browser API calls, and updates manifest, dependencies, and HTML to support Firefox (Gecko) and Blink-based browsers consistently.

Class diagram for unified storage abstraction and usage

classDiagram
    class browser {
        +storage
        +runtime
        +tabs
    }
    class storage {
        +local
    }
    class local {
        +get(keys, callback)
        +set(items, callback)
        +remove(keys, callback)
    }
    class scrumHelper {
        +storageGet(keys)
        +storageSet(items)
        +storageRemove(keys)
        +getStorageData()
        +saveToStorage(data, subject)
        +loadFromStorage()
    }
    browser o-- storage
    storage o-- local
    scrumHelper ..> browser : uses
    scrumHelper ..> storage : uses
    scrumHelper ..> local : uses
    class main {
        +handleBodyOnLoad()
        +handleEnableChange()
        +handleStartingDateChange()
        +handleEndingDateChange()
        +handleLastWeekContributionChange()
        +handleYesterdayContributionChange()
        +handleGithubUsernameChange()
        +handleGithubTokenChange()
        +handleProjectNameChange()
        +handleCacheInputChange()
        +handleOpenLabelChange()
        +handleUserReasonChange()
        +handleShowCommitsChange()
    }
    main ..> browser : uses
    main ..> storage : uses
    main ..> local : uses
Loading

File-Level Changes

Change Details Files
Unified browser storage into promise-based API wrappers
  • Introduced storageGet, storageSet, storageRemove helper functions
  • Replaced all chrome.storage.local.* callbacks with await storageGet/Set/Remove
  • Updated getCacheTTL, loadFromStorage, saveToStorage and forceGithubDataRefresh to use async/await
src/scripts/scrumHelper.js
src/scripts/main.js
src/scripts/popup.js
Added browser polyfill and configured manifest for Gecko
  • Added browser-polyfill.js file and dependency
  • Included browser-polyfill in content_scripts and popup.html
  • Added browser_specific_settings in manifest.json
src/scripts/browser-polyfill.js
src/manifest.json
package.json
src/popup.html
Refactored runtime and tabs APIs to promise-based browser calls
  • Replaced chrome.runtime.onMessage with runtime.onMessage
  • Replaced chrome.tabs.query/sendMessage/reload with browser.tabs methods
  • Converted callback logic to async/await flows
src/scripts/scrumHelper.js
src/scripts/main.js
Enhanced logging and error handling
  • Replaced console.log with log() wrapper and added logError
  • Guarded Materialize.toast calls with typeof checks
  • Added contextual log statements around storage and GitHub fetch
src/scripts/scrumHelper.js
Updated UI event bindings and cleanup
  • Switched from jQuery New conversation handler to plain DOM listeners
  • Replaced chrome.storage in main.js and popup.js with browser.storage
  • Cleaned up redundant whitespace and formatting inconsistencies
src/scripts/scrumHelper.js
src/scripts/main.js
src/scripts/popup.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Saksham-Sirohi - I've reviewed your changes - here's some feedback:

  • The allIncluded function has grown very large and handles multiple responsibilities—consider refactoring it into smaller, purpose-driven helper functions to improve readability and maintainability.
  • Storage calls are still mixed between direct browser.storage.local and the new storageGet/storageSet wrappers—unify all storage interactions through the wrapper API for consistency.
  • There’s repeated DOM selection and event-binding logic across main.js and popup.js—extract common utilities or modules to reduce duplication and simplify future changes.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The allIncluded function has grown very large and handles multiple responsibilities—consider refactoring it into smaller, purpose-driven helper functions to improve readability and maintainability.
- Storage calls are still mixed between direct browser.storage.local and the new storageGet/storageSet wrappers—unify all storage interactions through the wrapper API for consistency.
- There’s repeated DOM selection and event-binding logic across main.js and popup.js—extract common utilities or modules to reduce duplication and simplify future changes.

## Individual Comments

### Comment 1
<location> `src/scripts/scrumHelper.js:80` </location>
<code_context>
+    async function getStorageData() {
</code_context>

<issue_to_address>
getStorageData is called but not awaited, which may cause race conditions.

This could result in inconsistent state or errors. Please await getStorageData or restructure the function to ensure correct execution order.
</issue_to_address>

### Comment 2
<location> `src/scripts/scrumHelper.js:175` </location>
<code_context>
+            showCommits = false;
+        }

+        if (!items.showOpenLabel) {
+            showOpenLabel = false;
+            pr_open_button = '';
+            issue_opened_button = '';
+            pr_merged_button = '';
+            issue_closed_button = '';
+        }
+        if (items.githubCache) {
</code_context>

<issue_to_address>
Inconsistent variable naming for PR open button.

`pr_open_button` is set here, but the variable is previously defined as `pr_unmerged_button`. Please use consistent naming to avoid reference errors or UI issues.
</issue_to_address>

### Comment 3
<location> `src/scripts/scrumHelper.js:265` </location>
<code_context>

-
-    function saveToStorage(data, subject = null) {
+    async function saveToStorage(data, subject = null) {
         const cacheData = {
             data: data,
</code_context>

<issue_to_address>
saveToStorage does not propagate errors to callers.

Currently, errors are only logged and a boolean is returned. Consider throwing errors or implementing a clearer error-handling strategy so callers are properly informed of failures.

Suggested implementation:

```javascript
    async function saveToStorage(data, subject = null) {
        try {
            const cacheData = {
                data: data,
                cacheKey: githubCache.cacheKey,
                hasSubject: !!subject,
            };
            // Assuming storageSet is the function to save to storage
            await storageSet(cacheData, subject);
        } catch (error) {
            // Optionally log the error here if desired
            // console.error('Failed to save to storage:', error);
            throw error;
        }

```

- If `storageSet` is not the correct function to save to storage, replace it with the actual storage-saving function.
- Update all callers of `saveToStorage` to handle thrown errors (e.g., with try/catch).
- Remove any code that expects a boolean return value from `saveToStorage`, as it will now throw on error.
</issue_to_address>

### Comment 4
<location> `src/scripts/scrumHelper.js:1138` </location>
<code_context>
     allIncluded('email');
-    $('button>span:contains(New conversation)').parent('button').click(() => {
-        allIncluded();
+    document.querySelectorAll('button').forEach(button => {
+        if (button.textContent.includes('New conversation')) {
+            button.addEventListener('click', () => allIncluded());
+        }
     });
 }
</code_context>

<issue_to_address>
Selector for 'New conversation' button may be too broad.

This approach may bind events to unintended buttons if similar text appears elsewhere. Use a more precise selector or add checks to ensure only the intended button is targeted.

Suggested implementation:

```javascript
    document.querySelectorAll('button').forEach(button => {
        if (
            button.textContent.trim() === 'New conversation' &&
            button.closest('.conversation-toolbar') // Adjust this selector to match the actual parent/container
        ) {
            button.addEventListener('click', () => allIncluded());
        }
    });

```

- Replace `.conversation-toolbar` with the actual class or selector of the container that uniquely identifies the "New conversation" button, if different.
- If the button has a unique attribute (e.g., `data-testid="new-conversation"`), use `document.querySelector('button[data-testid="new-conversation"]')` instead for even more precision.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Saksham-Sirohi Saksham-Sirohi force-pushed the firefox-compatibility-addition branch 11 times, most recently from 13d4467 to 423fc91 Compare July 5, 2025 17:34
@Saksham-Sirohi Saksham-Sirohi force-pushed the firefox-compatibility-addition branch from 423fc91 to ea6d19d Compare July 5, 2025 17:35
@Saksham-Sirohi
Copy link
Contributor Author

sorry there was a lot changes detected due to my secondary editor's config which was causing sorcery to spit so many things out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant