Skip to content

Core Extension Framework

Relevant source files

The following files were used as context for generating this wiki page:

Purpose and Scope

This document describes the foundational architecture of the BiliScape extension, focusing on the core extension framework components that enable browser integration and essential background services. This includes the manifest files, background script functionality, browser action events, and context menu integration. For information about the UI system and its components, see UI System.

Framework Overview

The core extension framework serves as the foundation layer upon which all other BiliScape features are built. It handles browser integration, event handling, and provides background services that work even when the extension's UI is not open.

mermaid Diagram

Sources: manifest.json, manifest_firefox.json, js/background.js

Manifest Configuration

The manifest files serve as the extension's "blueprint" that defines its capabilities, permissions, and resource access. BiliScape provides two manifest files to support both Chrome/Chromium-based browsers and Firefox:

  • manifest.json - Standard manifest for Chrome and other Chromium-based browsers
  • manifest_firefox.json - Firefox-specific manifest with browser-specific configurations

Key Components of Manifest Files

Both manifests define:

  1. Extension metadata (name, version, description)
  2. Required permissions
  3. Host permissions (external domains the extension can access)
  4. Browser action definition
  5. Background script configuration
  6. Options page location

Cross-Browser Compatibility

The following table highlights the key differences between the Chrome and Firefox manifests:

FeatureChrome (manifest.json)Firefox (manifest_firefox.json)
Background ScriptUses service_worker propertyUses scripts array
Browser-specific SettingsNot requiredIncludes gecko configuration with id and strict_min_version
Options UIBasic configurationAdds browser_style: true
mermaid Diagram

Sources: manifest.json:1-33, manifest_firefox.json:1-42

Background Script Architecture

The background script (background.js) provides the extension's core functionality and runs independently of the main extension UI. It handles several key responsibilities:

Installation Event

The background script listens for the extension's installation event and opens a welcome page with version information:

mermaid Diagram

Sources: js/background.js:1-8

Context Menu Integration

BiliScape integrates with the browser's context menu to provide easy access to its features:

mermaid Diagram

Sources: js/background.js:11-59

Browser Action Handler

When users click the extension's icon in the browser toolbar:

mermaid Diagram

Sources: js/background.js:62-69

Notification System

The background script implements a notification system to alert users about new content:

mermaid Diagram

Sources: js/background.js:72-132

Configuration System

The background script includes a configuration system to retrieve user settings from the extension's storage:

mermaid Diagram

The configuration system is used to determine whether to enable notification features:

javascript
getConfig("player.Notify_Dynamic_Update", function(value){
    if(value) {
        checkForUpdates();
        setInterval(checkForUpdates, 20 * 60 * 1000);
    }
});

Sources: js/background.js:73-87, js/background.js:126-132

Extension Permissions

The core framework requires several browser permissions to function properly:

PermissionPurpose
notificationsEnable browser notifications for content updates
webRequestMonitor and modify web requests
declarativeNetRequestUse declarative rules to modify network requests
cookiesAccess cookies for Bilibili API authentication
contextMenusAdd items to the browser's context menu
tabsCreate and manage browser tabs
scriptingExecute scripts in the context of web pages
storageStore and retrieve user settings

Host permissions include:

  • *://*.bilibili.com/* - Access to Bilibili website and API
  • *://gitee.com/*/*/raw/* - Access to remote plugin repositories

Sources: manifest.json:10-22, manifest_firefox.json:10-22

Integration with Other Components

The core extension framework integrates with other BiliScape components through several mechanisms:

  1. UI Integration: The browser action handler opens the main extension UI (home.html).
  2. Media Player Integration: The context menu handler directs users to specific video or live stream content.
  3. Configuration System: Provides access to user settings for all components.
  4. API Access: Establishes the necessary permissions for Bilibili API interactions.

For more detailed information about other components:

Sources: js/background.js, manifest.json, manifest_firefox.json