Background
In the src/background/index.ts
file, we define the background
logic, such as tab management, message handling, etc.
Listen to messages, process messages through the defaultMessageHandler
function, handle tab management messages through the tabsManagerMessageHandler
function, and handle trusted domain messages through the trustDomainMessageHandler
function.
Browser extensions listen to messages through chrome.runtime.onMessage
, which can receive messages from content script
as well as messages from the options
page.
At the same time, we listen to tab update and delete events for tab management. When users use the browser's tab management functionality, these events are triggered, passing updated information to us for processing, such as reload, close, refresh, etc. To synchronize tab states in the Sidepanel
.
The keep-alive mechanism is to keep Background running continuously in the browser background and prevent it from being killed by the browser.