Skip to content

Pull request for issue #57#58

Merged
ochowei merged 6 commits into
mainfrom
bugfix/firefox-options-storage
Aug 27, 2025
Merged

Pull request for issue #57#58
ochowei merged 6 commits into
mainfrom
bugfix/firefox-options-storage

Conversation

@google-labs-jules

Copy link
Copy Markdown
Contributor

Fixes #57

The options page was not saving settings in Firefox because it directly used the `chrome.storage` API. This is not supported in Firefox, which requires the `browser.storage` API.

To resolve this, this change introduces `webextension-polyfill`, which provides a unified, promise-based `browser.*` API that works across both Chrome and Firefox.

The following changes were made:
- Added `webextension-polyfill` as a dev dependency.
- Updated `webpack.config.js` to bundle the polyfill with `options.js`.
- Refactored `src/options/options.js` to use the `browser.*` API with promises, replacing the `chrome.*` API with callbacks.
This commit addresses two issues preventing the options page from functioning correctly in Firefox:

1.  **API Incompatibility:** The options page was using the `chrome.storage` API, which is not supported in Firefox. This was resolved by introducing the `webextension-polyfill` to provide a cross-browser `browser.*` API. The options script (`src/options/options.js`) was refactored to use the promise-based `browser.storage` API.

2.  **Storage Sync Requirement:** The `storage.sync` API in Firefox requires a stable, explicit add-on ID in the manifest and will not work with the temporary ID assigned during development. This was fixed by updating `webpack.config.js` to dynamically add a `browser_specific_settings` block with a fixed ID to the `manifest.json` for Firefox builds.

With these changes, the options page now saves settings correctly in both Chrome and Firefox.
This commit resolves multiple issues to ensure the extension works correctly on both Chrome and Firefox.

1.  **Use `webextension-polyfill` for all scripts:**
    - Replaced all `chrome.*` API calls with the promise-based `browser.*` equivalent in `options.js`, `service-worker.js`, and `content-script.js`.
    - Updated `webpack.config.js` to bundle the polyfill with all three scripts, fixing a regression where `browser` was not defined in Chrome.

2.  **Add static Add-on ID for Firefox:**
    - Modified `webpack.config.js` to add a `browser_specific_settings` block to the manifest during Firefox builds. This provides the static ID required for the `storage.sync` API to function correctly during development.

These changes ensure that the options page and all other extension functionality work reliably and consistently across both Chrome and Firefox.
This commit resolves multiple issues to ensure the extension works correctly on both Chrome and Firefox.

1.  **Use `webextension-polyfill` for all scripts:**
    - Replaced all `chrome.*` API calls with the promise-based `browser.*` equivalent in `options.js`, `service-worker.js`, and `content-script.js`.
    - Updated `webpack.config.js` to bundle the polyfill with all three scripts, fixing a regression where `browser` was not defined in Chrome.

2.  **Add static Add-on ID for Firefox:**
    - Modified `webpack.config.js` to add a `browser_specific_settings` block to the manifest during Firefox builds. This provides the static ID required for the `storage.sync` API to function correctly during development.

These changes ensure that the options page and all other extension functionality work reliably and consistently across both Chrome and Firefox.
This commit provides a comprehensive fix for cross-browser compatibility issues, ensuring the extension works correctly on both Chrome and Firefox.

The key changes are:

1.  **Integrate `webextension-polyfill`:**
    - Added `webextension-polyfill` as a dependency.
    - Refactored all JavaScript files (`options.js`, `service-worker.js`, `content-script.js`) to import and use the `browser.*` API namespace, replacing the `chrome.*` namespace.
    - This resolves the `browser is not defined` error and standardizes API calls across browsers.

2.  **Update Build Configuration:**
    - Modified `webpack.config.js` to correctly handle the module-based imports.
    - Added logic to inject a static add-on ID into the `manifest.json` for Firefox builds, which is required for the `storage.sync` API to function during development.

This resolves the initial bug where settings would not save on Firefox, as well as subsequent regressions and errors that occurred during the development process.
This commit provides a comprehensive fix for cross-browser compatibility issues, ensuring the extension works correctly on both Chrome and Firefox.

The key changes are:

1.  **Integrate `webextension-polyfill`:**
    - Added `webextension-polyfill` as a dependency.
    - Refactored all JavaScript files (`options.js`, `service-worker.js`, `content-script.js`) to import and use the `browser.*` API namespace, replacing the `chrome.*` namespace.
    - This resolves the `browser is not defined` error and standardizes API calls across browsers.

2.  **Update Build Configuration:**
    - Modified `webpack.config.js` to correctly handle the module-based imports.
    - Added logic to inject a static add-on ID into the `manifest.json` for Firefox builds, which is required for the `storage.sync` API to function during development.

This resolves the initial bug where settings would not save on Firefox, as well as subsequent regressions and errors that occurred during the development process.
@ochowei ochowei merged commit ba27e44 into main Aug 27, 2025
3 checks passed
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.

[Bug] 選項頁面設定在 Firefox 中因 API 不相容而無法儲存

1 participant