Manifest V2 -> V3 - programatic modification of response headers

Skip to first unread message

Kayvan Mojarrad

Jun 10, 2024, 9:15:51 AMJun 10
to Chromium Extensions

I have a manifest v2 Chrome extension that uses blocking chrome.webRequest.onHeadersReceived to rewrite part of the Location header on responses from a matching url.

The use case is to intercept the redirection from an externally hosted login page (aws cognito hosted ui), and to modify the url host to localhost during development.

The redirect url has a query param appended (?code=xxxx) - code parameter is used in authorization_code grant type flow in order to acquire the tokens.

For this reason, I need to change the host in the Location header while preserving the query params.

I have not been able to find a way to do this using the new manifest v3 chrome.declarativeNetRequest.

Would anyone know if there is a way to do the same thing as the code below but in manifest v3?


const config = {filter: '*', rewrite: 'http://localhost:5137'};

    urls: [config.filter]
  ['blocking', 'responseHeaders', 'extraHeaders']

function rewriteLocationHost(data) {
  if (data.statusCode === 301 || data.statusCode === 302) {
    const header = data.responseHeaders.find(v => === 'location')
    if (header) {
      header.value = changeHost(header.value, config.rewrite)
  return {responseHeaders: data.responseHeaders}

function changeHost(url, newHost) {
const u = new URL(url)
  const i = url.indexOf( + + 1
  const newUrl = newHost + url.substring(i)
  return newUrl


Jun 10, 2024, 10:10:42 AMJun 10
to Chromium Extensions, Kayvan Mojarrad
No, this use case is broken in a conventional ManifestV3 extension that's not installed via policy, just like dozens of other advanced applications of webRequestBlocking that were dismissed as negligible by Chromium team. Hopefully, for regex find+replace inside headers of response or request will be implemented soon, given the fact that the developer working on DNR apparently has finished implementing

Kayvan Mojarrad

Jun 10, 2024, 10:18:37 AMJun 10
to Chromium Extensions, woxxom, Kayvan Mojarrad
Thanks, will keep an eye on
Reply all
Reply to author
0 new messages