Learnings from migrating Accessibility Insights for Web to Chrome’s Manifest V3

Learnings and takeways from migrating Accessibility Insights for Web from Chrome's Manifest V2 to Manifest V3.

Sarah Oslund
7 min readintermediate
--
View Original

Overview

The article discusses the migration of the Accessibility Insights for Web extension from Chrome's Manifest V2 to Manifest V3, detailing the architectural changes, challenges faced, and lessons learned during the process. Key topics include the transition from background pages to service workers, data storage strategies, event listener management, and the implications of these changes on performance and compatibility.

What You'll Learn

1

How to migrate a Chrome extension from Manifest V2 to Manifest V3

2

Why using IndexedDB is crucial for data persistence in service workers

3

How to manage event listeners effectively in a service worker environment

4

When to consider performance optimizations during service worker initialization

Prerequisites & Requirements

  • Understanding of Chrome extension architecture and service workers
  • Familiarity with IndexedDB and its API(optional)

Key Questions Answered

What are the main architectural changes when migrating to Manifest V3?
The primary architectural change involves transitioning from persistent background pages to service workers, which are not persistent and can shut down when idle. This necessitates new strategies for data storage and event listener management to ensure functionality and performance are maintained.
How does IndexedDB help with data persistence in service workers?
IndexedDB allows the extension to store data persistently across service worker lifetimes, addressing the issue of data loss when service workers shut down. This change required careful management of data updates to ensure performance was not significantly impacted.
What strategies were implemented to manage event listeners in MV3?
To manage event listeners effectively, the team registered placeholder handlers during service worker initialization. This approach deferred actual event handling until necessary asynchronous setup was complete, ensuring no events were missed during the initialization phase.
What performance considerations were made during the migration to MV3?
With MV3, service workers are initialized repeatedly, making background process initialization performance critical. The team minimized initialization time to enhance performance, which was less of a concern with the single initialization of background pages in MV2.

Technologies & Tools

Database
Indexeddb
Used for persistent data storage across service worker lifetimes.

Key Actionable Insights

1
Implement data storage using IndexedDB to ensure persistence across service worker lifetimes.
This is crucial as service workers can shut down when idle, leading to potential data loss. By using IndexedDB, developers can maintain necessary data even when the service worker is not active.
2
Register event listeners in the first event loop of the service worker to avoid missing events.
This practice is essential in MV3, as events may be missed if listeners are not registered before asynchronous calls. Using placeholder handlers can help manage this effectively.
3
Audit and refactor any 'fire and forget' listeners to properly track asynchronous work.
This prevents service workers from shutting down prematurely due to untracked async operations, ensuring that the extension remains responsive and functional.

Common Pitfalls

1
Failing to register event listeners before asynchronous calls can lead to missed events.
This happens because if listeners are not set up in the first event loop, any events that occur during initialization will not be captured, leading to functionality issues.
2
Neglecting performance optimizations during service worker initialization can degrade user experience.
As service workers are initialized repeatedly in MV3, slow initialization can lead to noticeable delays in extension responsiveness, impacting overall performance.

Related Concepts

Chrome Extensions
Service Workers
Indexeddb
Event Handling In Javascript