upgrade manifest-v3 for chrome
Summary
-
Update Manifest File
- Update
manifest.jsonto follow the MV3 format. - Adjust necessary APIs and permissions to be compatible with MV3.
- Update
-
Address MV3-Specific Changes
- Adapt to the use of service workers and address API removals or deprecations introduced in MV3.
- Add
public/external-script.jsto replace inline scripts, ensuring compliance with Content Security Policy (CSP).
Problem description
-
Warning Message
The Chrome Web Store displays a warning indicating that the extension does not align with the "best practices for Chrome extensions" because it is still using Manifest Version 2.- There is a risk that this extension may soon cease to be supported by Google.
-
MV2 Deprecation Timeline
Google has officially announced the deprecation of Manifest Version 2, and starting in 2024, support for extensions using MV2 will be discontinued.- Details can be found in the official documentation.
-
CSP Restrictions
Due to restrictions imposed by Content Security Policy (CSP), the execution of inline scripts is blocked.- In response, inline scripts were extracted into an external file,
external-script.js, that is now referenced externally.
- In response, inline scripts were extracted into an external file,
-
Impact on the Project
If this extension is not updated to Manifest Version 3, it may cease to function properly in the near future.
Pros/cons of approach implemented
[Pros]
- Improved Readability: More meaningful constant names and cleaner structure make the code easier to understand.
-
Reduced Duplication: Common logic, like
window.postMessage, is extracted into reusable functions, following the DRY principle. - CSP Compliance: By extracting inline scripts to an external file, the implementation adheres to CSP restrictions, reducing the risk of security issues.
[Cons]
- Increased Complexity: Introducing new utility functions and abstractions might make the code harder to understand for first-time readers, as it adds more layers of indirection.
- Maintenance Overhead: Managing separate external script files may add an additional maintenance burden.
Checklist
- [x] Is this PR a reasonable size?
Code Review Guidelines for Reviewers
- Try to review in a timely manner. Opinions/nitpicks should not be blockers. Pair on a call for non-trivial feedback.
- Overall design and approach should follow established patterns. Don't try to make the PR perfect.
- Try to identify edge cases, race conditions, over-engineering, lack of test coverage and complexity.
- If you don't feel qualified to review the code, pass it on to someone who is.