Open josephj opened 7 months ago
Manifest V3 Example:
For Manifest V3, you would use a similar setup, but with the host_permissions field in the manifest.json:
{ "manifest_version": 3, "name": "URL Redirector", "version": "1.0", "background": { "service_worker": "background.js" }, "permissions": [ "webRequest" ], "host_permissions": [ "*://*.example.com/*" ] }
And the background.js would use the chrome.declarativeNetRequest API instead:
chrome.declarativeNetRequest.onBeforeRequest.addListener( function(details) { const url = new URL(details.url); if (url.hostname === 'www.example.com') { const newUrl = url.href.replace('www.example.com', 'localhost:3000'); return { redirectUrl: newUrl }; } }, { urls: ["*://www.example.com/*.js"] }, // Pattern to match JS files from example.com ["blocking"] );
It seems the manifest.json v3 has blocked this feature. We probably can only achieve it in DevTools.
Manifest V3 Example:
For Manifest V3, you would use a similar setup, but with the host_permissions field in the manifest.json:
And the background.js would use the chrome.declarativeNetRequest API instead: