Manifest V3 是 Chrome 擴展的新規(guī)范,旨在提升安全性、性能和隱私保護。1. 核心變化是用 service worker 替代 background scripts,減少內(nèi)存占用;2. 內(nèi)容腳本限制動態(tài)執(zhí)行代碼,必須在 manifest.json 中明確聲明;3. 引入 declarativeNetRequest API 替代 webRequest,提前定義請求規(guī)則,提升安全但降低靈活性;4. 其他改動包括嚴(yán)格圖標(biāo)尺寸、禁止遠(yuǎn)程加載腳本及部分 API 棄用。開發(fā)者需盡早適配以應(yīng)對 V2 支持淘汰。
Manifest V3 是 Chrome 瀏覽器為擴展程序(extensions)推出的一個新版本格式規(guī)范,主要目的是提升瀏覽器的安全性、性能和隱私保護。它并不是一個簡單的升級,而是對擴展運行機制的較大調(diào)整,尤其影響了廣告攔截類、內(nèi)容修改類等依賴“后臺腳本”行為的擴展。

1. 核心變化:從 background scripts 到 service workers
在 Manifest V2 中,很多擴展使用 background pages 或 background scripts 來執(zhí)行長期任務(wù),比如監(jiān)聽網(wǎng)頁事件、管理彈出窗口等。這些頁面雖然功能強大,但會占用不少系統(tǒng)資源。

Manifest V3 的做法是用 service worker 替代 background scripts。Service worker 是一種輕量級、生命周期短的腳本環(huán)境,只有在需要時才被喚醒,處理完任務(wù)后就會暫停。這樣可以減少內(nèi)存占用,提高瀏覽器整體性能。
?? 注意:這意味著你不能再像以前那樣長時間運行一個腳本來監(jiān)聽各種事件了,得適應(yīng)新的“按需觸發(fā)”邏輯。
![]()
2. 內(nèi)容腳本(Content Scripts)的限制變多
在 V2 中,擴展可以直接注入 content script 到網(wǎng)頁中,并通過 eval()
執(zhí)行字符串代碼,這給一些高級功能提供了便利,但也帶來了安全隱患。
Manifest V3 對此做了限制:
- 不再允許使用
eval()
或new Function()
在 content script 中動態(tài)執(zhí)行代碼。 - 內(nèi)容腳本必須明確聲明在 manifest.json 文件中,不能動態(tài)生成。
如果你之前寫過自動填充、頁面分析類的插件,這部分可能需要重構(gòu)代碼結(jié)構(gòu)。
3. 引入 declarativeNetRequest API 替代 webRequest
對于廣告攔截類擴展來說,這是最重要的變化之一。
過去,它們通常使用 webRequest
API 攔截并阻止某些網(wǎng)絡(luò)請求。但這個 API 權(quán)限太大,可能會影響性能和隱私。
V3 引入了新的 declarativeNetRequest
API,它要求擴展提前定義好一組規(guī)則(最多三萬條),由瀏覽器來決定是否阻止或重定向請求。這種方式更安全、高效,但也意味著靈活性下降。
舉個例子:Adblock 類擴展現(xiàn)在不能實時判斷要不要攔截某個廣告鏈接,而是要提前把規(guī)則加載好,讓瀏覽器去執(zhí)行。
4. 其他小改動和注意事項
- 圖標(biāo)尺寸要求更嚴(yán)格:manifest v3 推薦使用 128x128 像素以上的 PNG 圖標(biāo),否則可能會有警告。
- 不允許遠(yuǎn)程加載腳本:所有 JS 腳本必須打包進(jìn)擴展本身,不能從外部服務(wù)器動態(tài)加載,防止惡意代碼注入。
-
部分 API 已棄用:如
chrome.extension.onRequest
和chrome.tabs.executeScript
的使用方式有所變化。
總的來說,Manifest V3 的目標(biāo)是讓 Chrome 擴展更安全、更高效,但它也確實給開發(fā)者帶來了一些挑戰(zhàn),特別是那些重度依賴后臺腳本和網(wǎng)絡(luò)攔截功能的項目。
如果你正在開發(fā)或維護一個 Chrome 插件,建議盡早適配 V3 規(guī)范,因為 Google 已經(jīng)逐步淘汰對 V2 的支持。
基本上就這些,改起來不難,但細(xì)節(jié)容易忽略。
The above is the detailed content of What is manifest v3 for Chrome extensions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Yandex (Яндекс) is Russia's largest search engine and the core of Russia's Internet ecosystem. Yandex is not just a search engine, it also provides a wide range of services, including maps, navigation, music, video, translation, cloud storage, payment systems, etc., covering almost all aspects of the daily life of Russian netizens. By logging in directly to Yandex, you can have a deeper understanding of Russia's Internet environment and obtain more accurate and localized search results.

To log in to AO3, first access the available mirrored sites, and then follow the steps: 1. Select the mirrored site and enter the URL; 2. Click the "Log In" button in the upper right corner of the homepage or in the navigation bar; 3. Enter the user name and password; 4. Select "Remember me" to automatically log in next time (but do not select public computers); 5. After confirming that the information is correct, click "Log In" to complete the login. If you encounter problems, you can check the network connection, confirm the correctness of the username and password, clear the browser cache and cookies, change the mirrored site, and try to use the Tor browser. In the end, you can contact AO3 customer service if it still cannot be resolved. In addition, when using AO3, you must respect the author's copyright and pay attention to content grading

The short video entrance of B station is mainly entered through the vertical screen short video mode (Story Mode) and dynamic publishing function. 1. There are three ways to enter the Story Mode: 1. Click the avatar icon in the upper left corner of the homepage to enter the vertical screen interface, which can slide to switch video and playback modes; 2. Click the video with the "vertical screen" label in the double column information flow of the homepage to enter directly; 3. Automatically enter when viewing published vertical screen videos through the personal homepage (can be turned off in settings). 2. Dynamically publishing short videos can be operated through the mobile phone or web page: 1. Click the "Publish" button in the upper right corner of the "My" page on the mobile phone and select the "Video" type to upload or shoot; 2. Click on the web page to submit and upload the video and edit and information settings. 3. Other entrances include partition browsing

The design philosophy of the Palipali platform is "user first, content is king". It knows that only by truly meeting user needs and providing high-quality content can we stand out in the fierce market competition. Therefore, Palipali strives to excel in content selection, striving to cover various types and meet the preferences of different users. Whether it is a classic old movie or the latest popular TV series; whether it is hot-blooded anime or casual games, Palipali can provide users with a wealth of choices.

Chrome Remote Desktop is a free remote desktop program from Google that runs as an extension that's paired with the Chrome web browser.You can use it to set up any computer running Chrome to be a host computer that you can connect to at any time, whe

Safari web browser is the default for the iPhone, iPad, and macOS, first released by Apple in 2003 and briefly offered on Windows from 2007 to 2012. The popularity of the Safari browser exploded with the iPhone and the iPad, and currently has about a

Pin Links to Pinterest Pinterest is often seen as a social media platform, but many users treat it as their go-to bookmarking service. Its layout is ideal for this purpose, letting you set up individual boards and pin links connected to images for si

Despite the presence of various search engines, the competition ultimately narrows down to two major players: Google and DuckDuckGo. Based on your specific requirements and preferences, Google might not necessarily be the optimal choice. DuckDuckGo h
