This would be one way to have a v2 example:
manifest.json
{
"background": {
"persistent": true,
"scripts": [ "background.js" ]
},
"description": "Header Test",
"homepage_url": "https://sermak.ca",
"icons": {
"128": "icon.png"
},
"manifest_version": 2,
"name": "Header Test",
"permissions": [ "webRequest", "webRequestBlocking", "tabs", "http://*/*", "https://*/*", "file:///*" ],
"short_name": "HT",
"version": "31.6"
}
background.js
// override User Agent
var OBSHOption = ["requestHeaders", "blocking"];
if (chrome.webRequest.OnBeforeSendHeadersOptions.hasOwnProperty("EXTRA_HEADERS")) OBSHOption.push("extraHeaders");
chrome.webRequest.onBeforeSendHeaders.addListener(function(details)
{
details.requestHeaders = details.requestHeaders.filter(function(elem) { return !elem.name.toLowerCase().includes("sec-ch-ua"); });
details.requestHeaders.find(function(elem) { if (elem.name.toLowerCase() == "user-agent") elem.value = "New Agent"; });
return {requestHeaders:details.requestHeaders};
}, {urls:["<all_urls>"]}, OBSHOption);
It's not fixed in v3 either,- I'm guessing it has to do with the "allow access to search results" and a bug in the Opera code that does sets this permission too late for headers to be modified, or something like that ...
In the meantime I've switched to Brave, but submitted a bug report.