如要讓擴充功能覆寫選取的 Chrome 設定,就必須覆寫設定。在 Windows 和 Mac 目前的所有 Chrome 版本中,都可以使用此 API。
首頁、搜尋引擎和起始網頁
以下是在擴充功能資訊清單中修改首頁、搜尋引擎和起始網頁的範例。凡是在 Settings API 中使用的網域,都必須透過發布擴充功能的開發人員帳戶驗證 (透過 Google Search Console)。請注意,如果您驗證了網域 (例如 https://example.com) 的擁有權,可以在擴充功能中使用任何子網域或網頁 (例如 https://app.example.com 或 https://example.com/page.html)。
使用設定覆寫權限,同時要求任何其他功能或權限,不符合我們的單一用途政策。當 Chrome 偵測到某個項目可能違反單一用途政策時,就會向使用者顯示確認對話方塊。如果擴充功能本身只能修改單一設定,而不尋找額外功能或權限,則不會收到確認對話方塊。
適用於 Chrome 107 以上版本。
{
"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",
...
}
自訂值
您可以透過以下方式自訂資訊清單中的值:
search_provider
、homepage
和startup_pages
屬性的所有值都可以使用chrome.i18n
API 進行本地化。針對外部擴充功能,
search_provider
、homepage
和startup_pages
網址值可使用登錄機碼參數化。在"update_url"
金鑰旁邊建立新的登錄項目 (請參閱這裡的操作說明)。索引鍵名稱為"install_parameter"
,這個值是任意字串:{ "update_url": "https://clients2.google.com/service/update2/crx", "install_parameter": "Value" }
資訊清單中的所有子字串
"__PARAM__"
都會替換為"install_parameter"
值。如果缺少"install_parameter"
,則移除"__PARAM__"
的例項。請注意,"__PARAM__"
不能做為主機名稱的一部分。必須在網址的第一個「/」之後出現。
參考資料
擴充功能可以覆寫資訊清單中的一或多項屬性:
alternate_urls
(字串陣列,選用)- 除了
search_url.
之外,還可使用的網址模式清單 encoding
(字串,選用)- 搜尋字詞使用的編碼。如未設定
prepopulated_id
,請務必填寫這個欄位。 favicon_url
(字串,選用)- 搜尋引擎的圖示網址。如未設定
prepopulated_id
,請務必填寫這個欄位。 homepage
(字串,選用)- 首頁的新值。
image_url
(字串,選用)- 搜尋引擎用於搜尋圖片的網址。如果選擇這個選項,則引擎不支援圖片搜尋功能。
image_url_post_params
(字串,選用)image_url
的 post 參數。is_default
(布林值,必要)- 指定是否要預設搜尋引擎。
keyword
(字串,選用)- 搜尋引擎的網址列關鍵字。如未設定
prepopulated_id
,請務必填寫這個欄位。 name
(字串,選用)- 向使用者顯示的搜尋引擎名稱。如未設定
prepopulated_id
,請務必填寫這個欄位。 prepopulated_id
(整數,選填)- Chrome 內建搜尋引擎的 ID。
search_provider
(物件,選用)- 搜尋引擎。
search_url
(字串,必要)- 搜尋引擎使用的搜尋網址。
search_url_post_params
(字串,選用)search_url
的 post 參數。startup_pages
(字串陣列,選用)- 陣列長度的陣列,包含要做為起始網頁使用的網址。
suggest_url
(字串,選用)- 搜尋引擎用來提供建議的網址。如果不使用,引擎不支援建議功能。
suggest_url_post_params
(字串,選用)suggest_url
的 post 參數。