Pull request for issue #57#58
Merged
Merged
Conversation
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.
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.
Fixes #57