动态

详情 返回 返回

Chrome 瀏覽器插件 V3 版本 Manifest.json 文件全字段解析 - 动态 详情

本文參與了SegmentFault 思否 2023 年度有獎徵文活動,歡迎正在閲讀的你也加入。
Chrome 瀏覽器插件 V3 版本 Manifest.json 文件全字段解析

Manifest.json 文件格式

每個擴展程序的根目錄中都必須有一個 manifest.json 文件,其中列出了有關該擴展程序的結構和行為的重要信息。

1、Demo 展示

1. 最小文件

{
  "manifest_version": 3,
  "name": "My Chrome Ext",
  "version": "1.0.0",
  "description": "Chrome Ext",
  "icons": {
    "48": "icon-48.png",
    "128": "icon-128.png"
  },
}

2. 增加 content_scripts

{
  "manifest_version": 3,
  "name": "Run script automatically",
  "description": "Add Context Scripts",
  "version": "1.0",
  "icons": {
    "16": "icon-16.png",
    "32": "icon-32.png",
    "48": "icon-48.png",
    "128": "icon-128.png"
  },
  "content_scripts": [
    {
      "js": [
        "content-script.js"
      ],
      "matches": [
        "http://*.example.com//"
      ]
    }
  ]
}

3. 增加 service_worker

{
  "manifest_version": 3,
  "name": "Click to run",
  "description": "Add Service Worker",
  "version": "1.0",
  "icons": {
    "16": "icon-16.png",
    "32": "icon-32.png",
    "48": "icon-48.png",
    "128": "icon-128.png"
  },
  "background": {
    "service_worker": "service-worker.js"
  },
  "action": {
    "default_icon": {
      "16": "icon-16.png",
      "32": "icon-32.png",
      "48": "icon-48.png",
      "128": "icon-128.png"
    }
  },
  "permissions": ["scripting", "activeTab"]
}

4. 增加 action

{
  "manifest_version": 3,
  "name": "Popup extension that requests permissions",
  "description": "Add Action",
  "version": "1.0",
  "icons": {
    "16": "icon-16.png",
    "32": "icon-32.png",
    "48": "icon-48.png",
    "128": "icon-128.png"
  },
  "action": {
    "default_popup": "popup.html"
  },
  "host_permissions": [
    "https://*.example.com/"
  ],
  "permissions": [
    "storage"
  ]
}

5. 增加側邊欄

{
  "manifest_version": 3,
  "name": "Side panel extension",
  "version": "1.0",
  "description": "Extension with a default side panel.",
  "icons": {
    "16": "images/icon-16.png",
    "48": "images/icon-48.png",
    "128": "images/icon-128.png"
  },
  "side_panel": {
    "default_path": "sidepanel.html"
  },
  "permissions": ["sidePanel"]
}

二、Manifest.json 文件字段及解析

1. Chrome 插件所必需的 key

1.1 manifest_version
  • 一個整數,用於指定擴展程序使用的清單文件格式版本。
  • 唯一支持的值是 3。
1.2 name
  • 一個字符串,用於在 Chrome 應用商店、安裝對話框和用户的 Chrome 擴展程序頁面 (chrome://extensions) 中標識擴展程序。
  • 長度上限為 45 個字符。
1.3 version
  • 一個字符串,用於標識擴展程序的版本號。
  • 一到四個以英文句點分隔的整數,用於標識此擴展程序的版本。下面幾條規則適用於整數:

    • 整數必須介於 0 到 65,535 之間(含 0 和 65,535)。
    • 非零整數不能以 0 開頭。例如,032 無效,因為它以零開頭。
    • 它們不能都為零。例如,0 和 0.0.0.0 是無效的,而 0.1.0.0 是有效的。
  • 以下是有效版本的一些示例:

    • "version": "1"
    • "version": "1.0"
    • "version": "2.10.2"
    • "version": "3.1.2.4567"
  • 比較從最左邊的整數開始。然後,如果這些整數相等,則比較右側的整數,依此類推。例如,1.2.0 是比 1.1.9.9999 更新的版本。
  • 缺少的整數等於零。例如,1.1.9.9999 比 1.1 更新,1.1.9.9999 低於 1.2。
"manifest_version": 3, 
"name": "My Chrome Ext Name", 
"version": "0.0.1",

2. Chrome 應用商店所需的 key

2.1 description
  • 一個 JSON 字符串,用於描述 Chrome 網上應用店和用户的擴展程序管理頁面上的擴展程序。
  • 長度上限為 132 個字符。

image.png

2.2 icons
  • 一個或多個代表擴展程序的圖標。
  • 建議使用 PNG 文件,但允許使用其他文件格式(SVGWebP 文件除外)。
  • 如果計劃在 Chrome 應用商店中分發擴展程序,則必須提供圖標。
    | 圖標大小 | 圖標的使用 |
    | --- | --- |
    | 16x16 | 擴展程序頁面和上下文菜單上的網站圖標。 |
    | 32x32 | Windows 計算機通常需要此大小。 |
    | 48x48 | 顯示在“擴展程序”頁面上。 |
    | 128x128 | 安裝時會顯示在 Chrome 應用商店中。 |
{
  "manifest_version": 3,
  "name": "chrome extension",
  "version": "0.0.1",
  "description": "My Chrome Extension description",
  "icons": {
    "16": "public/icons/icon_16.png",
    "32": "public/icons/icon_32.png",
    "48": "public/icons/icon_48.png",
    "128": "public/icons/icon_128.png"
  }
}

3. Chrome 插件可選 key

3.1 action
  • 定義擴展程序圖標在 Google 工具欄中的外觀和行為。
  • action 鍵(及其子項)是可選的。如果未添加此擴展程序,相應擴展程序仍會顯示在工具欄中,以便用户訪問此擴展程序的菜單。因此,建議始終至少包含 actiondefault_icon 鍵。
  • 【# Chrome 瀏覽器插件 V3 版本 Manifest.json 文件中 Action 字段解析類型(Types)、方法(Methods)和事件(Events)】
{
  "name": "Action Extension",
  "action": {
    "default_icon": {              
      "16": "images/icon16.png",   
      "24": "images/icon24.png",   
      "32": "images/icon32.png"    
    },
    "default_title": "Click Me",   
    "default_popup": "popup.html"  
  },
}
popup.html 是點擊 chrome 按鈕彈出的頁面

image.png

3.2 author
  • 指定用於創建擴展程序的帳號的電子郵件地址。
{
  "author": {
    "email": "user@example.com"
  },
}
3.3 background
  • 指定包含擴展程序的 Service Worker(充當事件處理程序)的 JavaScript 文件。
  • 【Chrome 瀏覽器插件 Manifest V3 版本新增中的 Service Worker 字段及解析】
  "background": {
    "service_worker": "service-worker.js",
    "type": "module"
  }
3.4 chrome_settings_overrides
  • 定義所選 Chrome 設置的替換項。
  • 設置覆蓋是擴展程序的一種覆蓋所選 Chrome 設置的方式。該 API 適用於 WindowsMac 的所有當前版本的 Chrome
  • search_providerhomepagestartup_pages 屬性的所有值都可以使用 chrome.i18nAPI 進行本地化。
  • 對於外部擴展程序,可以使用註冊表項對 search_providerhomepagestartup_pages 網址值進行參數化。
  • 可替換屬性列表:

    • alternate_urls(字符串數組,可選)

      • search_url. 之外,還可使用的網址格式列表
    • encoding(字符串,可選)

      • 用於搜索字詞的編碼。如果沒有設置 prepopulated_id,則必須執行此操作。
    • favicon_url(字符串,可選)

      • 搜索引擎的圖標網址。如果沒有設置 prepopulated_id,則必須執行此操作。
    • homepage(字符串,可選)

      • 首頁的新值。
    • image_url(字符串,可選)

      • 搜索引擎用於圖片搜索的網址。如果不這樣做,則表示引擎不支持圖片搜索。
    • image_url_post_params(字符串,可選)

      • image_urlpost 參數。
    • is_default(布爾值,必需)

      • 指定是否應將搜索服務提供商設置為默認搜索引擎。
    • keyword(字符串,可選)

      • 搜索引擎的多功能框關鍵字。如果沒有設置 prepopulated_id,則必須執行此操作。
    • name(字符串,可選)

      • 向用户顯示的搜索引擎的名稱。如果沒有設置 prepopulated_id,則必須執行此操作。
    • prepopulated_id(整數,可選)

      • Chrome 內置搜索引擎的 ID
    • search_provider(對象,可選)

      • 搜索引擎。
    • search_url(字符串,必需)

      • 搜索引擎使用的搜索網址。
    • search_url_post_params(字符串,可選)

      • search_urlpost 參數。
    • startup_pages(字符串數組,可選)

      • 一個長度為 1 的數組,其中包含將用作啓動頁的網址。
    • suggest_url(字符串,可選)

      • 搜索引擎用於獲取建議的網址。如果未使用此屬性,則引擎不支持建議。
    • suggest_url_post_params(字符串,可選)

      • suggest_urlpost 參數。
{
  "name": "My extension",
  "chrome_settings_overrides": {
    "homepage": "https://www.homepage.com",
    "search_provider": {
        "name": "name.__MSG_url_domain__",
        "keyword": "keyword.__MSG_url_domain__",
        "search_url": "https://www.foo.__MSG_url_domain__/s?q={searchTerms}",
        "favicon_url": "https://www.foo.__MSG_url_domain__/favicon.ico",
        "suggest_url": "https://www.foo.__MSG_url_domain__/suggest?q={searchTerms}",
        "instant_url": "https://www.foo.__MSG_url_domain__/instant?q={searchTerms}",
        "image_url": "https://www.foo.__MSG_url_domain__/image?q={searchTerms}",
        "search_url_post_params": "search_lang=__MSG_url_domain__",
        "suggest_url_post_params": "suggest_lang=__MSG_url_domain__",
        "instant_url_post_params": "instant_lang=__MSG_url_domain__",
        "image_url_post_params": "image_lang=__MSG_url_domain__",
        "alternate_urls": [
          "https://www.moo.__MSG_url_domain__/s?q={searchTerms}",
          "https://www.noo.__MSG_url_domain__/s?q={searchTerms}"
        ],
        "encoding": "UTF-8",
        "is_default": true
    },
    "startup_pages": ["https://www.startup.com"]
   },
   "default_locale": "de",
}
3.5 chrome_url_overrides
  • 定義默認 Chrome 網頁的替換項。
3.5.1 擴展程序可以使用 HTML 覆蓋網頁來替換 Google Chrome 通常提供的網頁。

擴展程序可以覆蓋以下任意網頁,但每個擴展程序只能覆蓋 1 個網頁:

  • 書籤

    • 用户從 Chrome 菜單中選擇“書籤管理器”菜單項(或者在 Mac 上)從“書籤”菜單中選擇“書籤管理器”菜單項時顯示的網頁。也可以通過輸入網址 chrome://bookmarks 來訪問此頁面。
  • 歷史記錄

    • 用户從 Chrome 菜單中選擇“歷史記錄”菜單項(或在 Mac 上從“歷史記錄”菜單中選擇“顯示全部歷史記錄”)時顯示的頁面。也可以通過輸入網址 chrome://history 來訪問此頁面。
  • 新的標籤頁

    • 用户創建新標籤頁或窗口時顯示的頁面。也可以通過輸入網址 chrome://newtab 來訪問此頁面。
{
  "manifest_version": 3,
  "name": "My extension",
  "chrome_url_overrides" : {
    "PAGE_TO_OVERRIDE": "myPage.html"
  },
}

PAGE_TO_OVERRIDE 替換為以下項之一:

  • bookmarks
  • history
  • newtab
3.6 commands
  • 定義擴展程序中的鍵盤快捷鍵。
  • commands API 可用於添加可觸發擴展程序中操作的鍵盤快捷鍵,例如,打開瀏覽器操作或向擴展程序發送命令的操作。
  • 必須在 manifest.json 聲明 commands,才能使用此 API
  • 【Chrome 瀏覽器插件 V3 版本 Manifest.json 中 Commands API 字段解析及對應的 Types、Methods 和 Events】
"commands": {
  "run-foo": {
    "suggested_key": {
      "default": "Ctrl+Shift+Y",
      "mac": "Command+Shift+Y"
    },
    "description": "Run "foo" on the current page."
  }
}
3.7 content_scripts
  • 指定在用户打開某些網頁時要使用的 JavaScriptCSS 文件。
  • 【Chrome 插件 V3 版本 Manifest.json 中的內容腳本(Content Scripts)解析】

    {
     "name": "My extension",
     "content_scripts": [
     {
       "matches": ["https://*.nytimes.com/*"],
       "css": ["my-styles.css"],
       "js": ["content-script.js"]
     }
     ]
    }
    3.8 content_security_policy
  • 定義對擴展程序可以使用的腳本、樣式和其他資源的限制。
  • 可以為擴展程序網頁和沙盒化擴展程序網頁定義單獨的可選策略。

    3.8.1 默認策略

如果沒有在 manifest.json 中定義 content_security_policy,將使用默認屬性,默認值為:

{
  "content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self';",
    "sandbox": "sandbox allow-scripts allow-forms allow-popups allow-modals; script-src 'self' 'unsafe-inline' 'unsafe-eval'; child-src 'self';"
  }
}

在這種情況下,擴展程序只會從自己的打包資源加載本地腳本和對象。WebAssembly 將停用,該擴展程序將不會運行內嵌 JavaScript,也無法將字符串評估為可執行代碼。如果添加了沙盒頁面,頁面將擁有更寬鬆的權限,可以從擴展程序外部評估腳本。

3.8.2 自定義策略

Chrome 對擴展程序頁面強制執行最低的內容安全政策。這相當於在 manifest.json 中指定以下策略:

{
  "content_security_policy": {
    "extension_pages": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self';"
  }
}

extension_pages 策略的放寬限制不能超過此最小值。

3.9 cross_origin_embedder_policy
  • 指定 Cross-Origin-Embedder-Policy HTTP 標頭的值,該標頭用於配置在擴展程序頁面中嵌入跨源資源。
  • require-corp
  • credentialless
  • unsafe-none

    {
    
      "cross_origin_embedder_policy": {
        "value": "require-corp"
      },
    
    }
    3.10 cross_origin_opener_policy
  • 指定 Cross-Origin-Opener-Policy HTTP 標頭的值,可讓確保頂級擴展程序頁面不會與跨源文檔共享瀏覽上下文組。
  • same-origin
  • same-origin-allow-popups
  • restrict-properties
  • unsafe-none

    {
      "cross_origin_opener_policy": {
        "value": "same-origin"
      },
    }
3.11 declarative_net_request
  • 定義 declarativeNetRequest API 的靜態規則,以允許攔截和修改網絡請求。

    {
    "name": "My extension",
    "declarative_net_request" : {
      "rule_resources" : [{
        "id": "ruleset_1",
        "enabled": true,
        "path": "rules_1.json"
      }, {
        "id": "ruleset_2",
        "enabled": false,
        "path": "rules_2.json"
      }]
    },
    "permissions": [
      "declarativeNetRequest",
      "declarativeNetRequestFeedback",
    ],
    "host_permissions": [
      "http://www.blogger.com/*",
      "http://*.google.com/*"
    ],
    }
3.12 default_locale
  • 一個字符串,用於定義支持多個語言區域的擴展程序的默認語言。例如 enpt_BR
  • 如果擴展程序具有 _locales 目錄,則 Manifest.json 必須定義 default_locale
3.13 devtools_page
  • 定義使用 DevTools API 的頁面。
  • 使用devtools.panels API 創建面板並與之交互,包括將其他擴展程序頁面作為面板或邊欄添加到開發者工具窗口中。
  • 使用 devtools.inspectedWindow API 獲取已檢查窗口的相關信息,並評估所檢查窗口中的代碼。
  • 使用 devtools.network API 獲取有關網絡請求的信息。
  • 使用 devtools.recorder API 擴展 Recorder面板。

    {
    "name": "Chrome Ext",
    "version": "1.0",
    "devtools_page": "devtools.html",
    }
3.14 export
  • 允許從擴展程序導出資源。
{
  "version": "1.0",
  "name": "My Shared Module",
  "export": {
    // Optional list of extension IDs explicitly allowed to
    // import this Shared Module's resources.  If no allowlist
    // is given, all extensions are allowed to import it.
  "allowlist": [
    "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
    "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
  ]
}
// Note: no permissions are allowed in Shared Modules
}
3.15 externally_connectable
  • 指定哪些其他頁面和擴展程序可以通過 runtime.connectruntime.sendMessage 連接到擴展程序。
  • 如果未在擴展程序的清單中聲明 externally_connectable 鍵,則所有擴展程序都可以連接,但任何網頁都無法連接。
  • 在更新清單以使用 externally_connectable 時,如果未指定 ids: ["*"],其他擴展程序將無法連接到擴展程序。
  • 屬性:

    • ids

      • 允許連接的擴展程序的 ID。如果留空或未指定,則任何擴展程序或應用都無法連接。通配符 * 將允許所有擴展程序和應用連接。
    • matches

      • 允許連接的網頁的網址格式。如果留空或未指定,則任何網頁都無法連接。格式不能包含通配符網域,也不能包含(有效)頂級域名的子網域。
✅ 有效網址 ❌ 網址無效
*://example.com/ *://example.com/one/
http://*.example.org/* <all_urls>
https://example.com/* http://*/*
  • accepts_tls_channel_id

    • 允許擴展程序使用與其連接的網頁的 TLS 通道 ID
{
  "name": "My externally connectable extension",
  "externally_connectable": {
    "ids": [
      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
    ],
    // If this field is not specified, no web pages can connect.
    "matches": [
      "https://*.google.com/*",
      "*://*.chromium.org/*",
    ],
    "accepts_tls_channel_id": false
  },
}
3.16 homepage_url
  • 一個字符串,用於指定擴展程序首頁的網址。
  • 如果未定義,則首頁默認是擴展程序的 Chrome 應用商店頁面。如果在自己的網站上託管擴展程序,此字段特別有用。
{
  "manifest_version": 3,
  "name": "chrome extension",
  "version": "0.1.0",
  "description": "My Chrome Extension",
  "homepage_url": "https://guoqiankun.blog.csdn.net/",
}
  • image.png
3.17 host_permissions
  • 列出擴展程序可以與之互動的網頁(使用網址匹配模式定義)。系統會在安裝時請求這些網站的用户權限。
  • permissions

    • 包含已知字符串列表中的項。更改可能會觸發警告。
  • optional_permissions

    • 由用户在運行時(而不是在安裝時)授予。
  • content_scripts.matches

    • 包含一個或多個匹配模式,可允許內容腳本注入到一個或多個主機中。更改可能會觸發警告
  • host_permissions

    • 包含一個或多個匹配模式,可提供對一個或多個主機的訪問權限。更改可能會觸發警告
  • optional_host_permissions

    • 由用户在運行時(而不是在安裝時)授予。
  • 【Chrome 瀏覽器插件 Manifest.json V3 中權限(Permissions)字段解析】
{
  "name": "Permissions Extension",
  "permissions": [
    "activeTab",
    "contextMenus",
    "storage"
  ],
  "optional_permissions": [
    "topSites",
  ],
  "host_permissions": [
    "https://www.developer.chrome.com/*"
  ],
  "optional_host_permissions":[
    "https://*/*",
    "http://*/*"
  ],
  "manifest_version": 3
}
3.18 import
  • 允許將資源導入擴展程序。
{
  "version": "1.0",
  "name": "My Importing Extension",
  "import": [
    {"id": "cccccccccccccccccccccccccccccccc"},
    {"id": "dddddddddddddddddddddddddddddddd"
      "minimum_version": "0.5" // optional
    },
  ]
}
3.19 incognito
  • 定義擴展程序在無痕模式下的行為。
  • 支持的值包括 spanningsplitnot_allowed

    {
    "incognito": "not_allowed"
    }
    3.20 key
  • 為各種開發用例指定擴展程序的 ID

    • 將服務器配置為僅接受來自 Chrome 擴展程序來源的請求。
    • 以便其他擴展程序或網站向擴展程序發送消息
    • 讓網站可以訪問擴展程序的 web_accessible_resources
    {
    "manifest_version": 3,
    "key": "ThisKeyIsChromeKey",
    }
3.21 minimum_chrome_version
  • 定義可安裝擴展程序的最低 Chrome 版本。
  • 該值必須是現有 Chrome 瀏覽器版本字符串的子字符串,例如 "107" 或 "107.0.5304.87"。
  • 如果用户的 Chrome 版本低於最低版本,則會在 Chrome 應用商店中看到“不兼容”警告,並且無法安裝擴展程序。如果將此擴展程序添加到現有擴展程序,則所用 Chrome 版本較低的用户將不會收到擴展程序的自動更新。

    {
    "minimum_chrome_version": "120.0.6099.129"
    }
    3.22 oauth2
  • 允許使用 OAuth 2.0 安全 ID
  • 此鍵的值必須是具有 "client_id" 和 "scopes" 屬性的對象。

    {
    "name": "OAuth Tutorial FriendBlock",
    ...
    "oauth2": {
      "client_id": "yourExtensionOAuthClientIDWillGoHere.apps.googleusercontent.com",
      "scopes":[""]
    },
    }
    3.23 omnibox
  • 允許此擴展程序在 Chrome 的地址欄中註冊關鍵字。

    {
    "omnibox": { "keyword": "newTab" },
    }
3.24 optional_host_permissions
  • 為擴展程序聲明可選的主機權限

    {
    "optional_host_permissions":[
      "https://*/*",
      "http://*/*"
    ],
    }
    3.25 optional_permissions
  • 為擴展程序聲明可選權限

    {
    "optional_permissions": [
      "topSites",
    ],
    }
    3.26 options_page
  • 指定 options.html 文件的路徑,以將擴展程序用作選項頁面。
  • image.png
{
  "options_page": "index.html",
}
3.27 options_ui
  • 指定 HTML 文件的路徑,該文件允許用户在 Chrome 擴展程序頁面更改擴展程序選項。
{
  "name": "My extension",
  "options_ui": {
    "page": "options.html",
    "open_in_tab": false
  },
}
3.28 permissions
  • 允許使用特定的擴展程序 API
  • 【Chrome 瀏覽器插件 Manifest.json V3 中權限(Permissions)字段解析】
"permissions": [
  "storage",
  "activeTab",
  "scripting"
]
3.29 requirements
  • 列出使用擴展程序所需的技術。
"requirements": {
  "3D": {
    "features": ["webgl"]
  }
}
3.30 sandbox
  • 定義一組擴展程序頁面,它們無權訪問擴展程序 API 或直接訪問非沙盒化頁面。
  • 擴展程序的沙盒化網頁使用的內容安全政策在 content_security_policy 鍵中指定。
  • 處於沙盒環境中會產生以下兩個影響:

    • 沙盒化頁面將無權訪問擴展程序 API,也無法直接訪問未經過沙盒化的頁面(可通過 postMessage() 與它們進行通信)。
    • 沙盒化頁面不受擴展程序其餘部分使用的內容安全政策 (CSP)(有自己的單獨的 CSP 值)的約束。這意味着,例如,它可以使用內嵌腳本和 eval
{
  "content_security_policy": {
    "sandbox": "sandbox allow-scripts; script-src 'self' https://example.com"
  },
  "sandbox": {
    "pages": [
      "page1.html",
      "directory/page2.html"
    ]
  },
}
3.31 short_name
  • 一個字符串,包含要在字符空間有限時使用的擴展程序名稱的縮寫版本。
  • 長度上限為 12 個字符。如果未定義,將顯示 name 鍵的截斷版本。

    {
    "short_name": "short name"
    }
    3.32 side_panel
  • 標識要在 sidePanel 中顯示的 HTML 文件。
{
  "name": "My side panel extension",
  "side_panel": {
    "default_path": "sidepanel.html"
  }
}
3.33 storage
  • 聲明託管存儲區域的 JSON 架構。
{
  "name": "My enterprise extension",
  "storage": {
    "managed_schema": "schema.json"
  },
}
3.34 tts_engine
  • 將擴展程序註冊為文字轉語音引擎。
{
  "name": "My TTS Engine",
  "version": "1.0",
  "permissions": ["ttsEngine"],
  "tts_engine": {
    "voices": [
      {
        "voice_name": "Alice",
        "lang": "en-US",
        "event_types": ["start", "marker", "end"]
      },
      {
        "voice_name": "Pat",
        "lang": "en-US",
        "event_types": ["end"]
      }
    ]
  },
  "background": {
    "page": "background.html",
    "persistent": false
  }
}
3.35 update_url
  • 一個字符串,其中包含擴展程序的更新頁面的網址。
  • 如果是在 Chrome 應用商店之外託管擴展程序,需要添加此字段。

    {
    "name": "My extension",
    "update_url": "https://myhost.com/mytestextension/updates.xml",
    }
    3.36 version_name
  • 一個描述擴展程序版本的字符串。例如 1.0 betabuild rc2
  • 如果未指定,則改為在擴展程序管理頁面上顯示 version 值。

    {
    "version_name": "1.0 beta"
    }
    3.37 web_accessible_resources
  • 定義擴展程序中可供網頁或其他擴展程序訪問的文件。
{
  "web_accessible_resources": [
    {
      "resources": [ "test1.png", "test2.png" ],
      "matches": [ "https://web-accessible-resources-1.glitch.me/*" ]
    }, {
      "resources": [ "test3.png", "test4.png" ],
      "matches": [ "https://web-accessible-resources-2.glitch.me/*" ],
      "use_dynamic_url": true
    }
  ],
}

4. ChromeOS 可選的 Key

4.1 file_browser_handlers
  • 提供對 fileBrowserHandler API 的訪問權限,該 API 允許擴展程序訪問 ChromeOS 文件瀏覽器。

    {
    "name": "My extension",
    "file_browser_handlers": [
      {
        "id": "upload",
        "default_title": "Save to Gallery", // What the button will display
        "file_filters": [
          "filesystem:*.jpg",  // To match all files, use "filesystem:*.*"
          "filesystem:*.jpeg",
          "filesystem:*.png"
        ]
      }
    ],
    "permissions" : [
      "fileBrowserHandler"
    ],
    }
    4.2 file_handlers
  • 指定 ChromeOS 擴展程序要處理的文件類型。
"file_handlers": [
  {
    "action": "/open_text.html",
    "name": "Plain text",
    "accept": {
      "text/plain": [".txt"]
    }
    "launch_type": "single-client"
  }
]
4.3 file_system_provider_capabilities
  • 允許訪問 fileSystemProvider API,以便擴展程序創建 ChromeOS 可以使用的文件系統。

    {
    "name": "My extension",
    "permissions": [
      "fileSystemProvider"
    ],
    "file_system_provider_capabilities": {
      "configurable": true,
      "watchable": false,
      "multiple_mounts": true,
      "source": "network"
    },
    }
    4.4 input_components
  • 允許使用 Input Method Editor API
{
  "input_components": [{
    "name": "ToUpperIME",
    "id": "ToUpperIME",
    "language": "en",
    "layouts": ["us::eng"]
  }]
}

引用

  • 【manifest】
user avatar littlelyon 头像 anchen_5c17815319fb5 头像 wojiaocuisite 头像 huaweiclouddeveloper 头像 wuyagege 头像 dalidexiaoxiami 头像 _6085362b65292 头像 meathill 头像 guisijun 头像 pxzsl 头像 lizeze 头像 sugar_coffee 头像
点赞 15 用户, 点赞了这篇动态!
点赞

Add a new 评论

Some HTML is okay.