clients
clients copied to clipboard
[PM-5880] Refactor browser platform utils service to remove `window` references
Type of change
- [ ] Bug fix
- [ ] New feature development
- [x] Tech debt (refactoring, code cleanup, dependency upgrades, etc)
- [ ] Build/deploy pipeline (DevOps)
- [ ] Other
Objective
The goal for this ticket is to remove a direct dependency on the window object within the BrowserPlatformUtilsService. To do this, we are refactoring the typing information within the service, adjusting how the service is instantiated to remove dependence on the window object, and reworking the clipboard related methods to conditionally use the chrome.offscreen API when we the extension is built using manifest v3.
Code changes
- apps/browser/src/autofill/background/overlay.background.spec.ts: Removing a reference to the
windowobject when handling a copy to clipboard action - apps/browser/src/autofill/background/overlay.background.ts: Removing a reference to the
windowobject when handling a copy to clipboard action - apps/browser/src/autofill/background/web-request.background.ts: Updating how we identify if the manifest version is mv2
- apps/browser/src/background/commands.background.ts: Removing a reference to the
windowobject when handling a copy to clipboard action - apps/browser/src/background/main.background.ts: Updating various element to change how we identify if the manifest version is for mv2 or mv3 and removing references to the
windowobject that directly affect theBrowserPlatformUtilsServiceclass. - apps/browser/src/background/runtime.background.ts: Removing a reference to the
windowobject when handling a copy to clipboard action - apps/browser/src/manifest.v3.json: Adding the
offscreenAPI to the manifest - apps/browser/src/platform/alarms/alarm-state.ts: Updating how we identify if the manifest version is mv3
- apps/browser/src/platform/background.ts: Updating how we identify if the manifest version is mv3
- apps/browser/src/platform/background/service-factories/storage-service.factory.ts: Updating how we identify if the manifest version if mv3
- apps/browser/src/platform/browser/browser-api.spec.ts: Adding Jest tests to validate the changes within the
BrowserApiclass. - apps/browser/src/platform/browser/browser-api.ts: Implementing an
isManifestVersionmethod that simplifies checking for mv3, as well as methods for creating and closing offscreen documents as needed. - apps/browser/src/platform/decorators/session-sync-observable/session-syncer.ts: Updating how we identify if the manifest version is mv3
- apps/browser/src/platform/globals.d.ts: Adding a custom declaration to indicate potentially expected values in for the
ServiceWorkerGlobalScope. This likely should be updated at some point, but scoping down the expected service worker scope to specific files, especially when they might switch between mv2 and mv3, has proven difficult. - apps/browser/src/platform/offscreen-document/abstractions/offscreen-document.ts: Adding typing information for the script used within the offscreen document
- apps/browser/src/platform/offscreen-document/index.html: The markup for the offscreen document
- apps/browser/src/platform/offscreen-document/offscreen-document.spec.ts: Jest tests validating the currently established behavior within the offscreen document script
- apps/browser/src/platform/offscreen-document/offscreen-document.ts: Implemented behavior that facilitates the ability to trigger the clipboard copy to and read from actions from the offscreen document.
- apps/browser/src/platform/popup/browser-popup-utils.ts: Updating how we identify if the manifest version is mv3
- apps/browser/src/platform/services/browser-clipboard.service.spec.ts: Jest tests for the
BrowserClipboardServiceclass - apps/browser/src/platform/services/browser-clipboard.service.ts: Refactored implementation for the browser clipboard behavior out of the
BrowserPlatformUtilsServiceclass. The two public methodscopyandreadfirst attempt to enact their behavior using the Clipboard API, and on failure will fallback to legacy methods. This allows us to have the same behavior within theBrowserPlatformUtilsServiceclass as well as the offscreen document. - apps/browser/src/platform/services/browser-platform-utils.service.spec.ts: Jest tests to validate the changes made to the
BrowserPlatformUtilsServiceclass - apps/browser/src/platform/services/browser-platform-utils.service.ts: Worked through re-typing the usage of
windowobjects throughout the script, and reworked the copy/read from clipboard functionality. - apps/browser/test.setup.ts: Adding chrome extension api scaffolding for the test runner
- apps/browser/webpack.config.js: Adding a conditional build of the offscreen document script and html if we are building the extension for manifest v3.
Codecov Report
Attention: Patch coverage is 85.60606% with 19 lines in your changes are missing coverage. Please review.
Project coverage is 25.31%. Comparing base (
940fd21) to head (44c9fc3).
Additional details and impacted files
@@ Coverage Diff @@
## main #7885 +/- ##
==========================================
+ Coverage 25.15% 25.31% +0.15%
==========================================
Files 2252 2254 +2
Lines 65846 65894 +48
Branches 12414 12415 +1
==========================================
+ Hits 16566 16679 +113
+ Misses 47938 47870 -68
- Partials 1342 1345 +3
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Checkmarx One – Scan Summary & Details – e867bff9-5a2c-4379-9c1e-96d23fe3ae6e
New Issues
| Severity | Issue | Source File / Package | Checkmarx Insight |
|---|---|---|---|
![]() |
Client_Privacy_Violation | /apps/browser/src/background/runtime.background.ts: 317 | Attack Vector |
Fixed Issues
| Severity | Issue | Source File / Package |
|---|---|---|
![]() |
Client_Privacy_Violation | /apps/browser/src/background/runtime.background.ts: 317 |
