Opera extensions fail to modify requestHeaders on google.com ...
-
escape75 last edited by
There is a fairly serious issue that's affecting Opera 109.x and earlier editions, and it surfaces when an extension is installed that modifies the User-Agent header. For v2 extensions that use chrome.webRequest.onBeforeSendHeaders, as well as v3 extensions chrome.declarativeNetRequest via modifyHeaders, the extension is able to modify all requestHeaders as expected except headers on google.com domain, but the issue is only with the initial request, all subsequent modifications are fine. This causes unexpected service issues with Google websites, as google receives different User-Agent header responses. Allow access to search page results is already enabled. This also includes not being able to add other headers, cookies, etc. If more information is needed please contact me. This issue does not exist in Chrome or Edge browsers. A quick way to test for this error is to search "what is my user agent" on google.com and notice how the UA is never modified as expected.
-
burnout426 Volunteer last edited by
@escape75 said in Opera extensions fail to modify requestHeaders on google.com ...:
A quick way to test for this error is to search "what is my user agent" on google.com and notice how the UA is never modified as expected.
I've noticed that too for a long time with https://addons.opera.com/en/extensions/details/user-agent-switcher-5/ for example (when set to Chrome for Windows and then clicking the pencil icon (edit) to set the string to
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
(what Chrome Stable says at the URLchrome://version
))."Allow access to search page results" doesn't help and neither does going to the URL
opera://browserjs
and disabling browser.js (to disable any user-agent workarounds Opera might have for Google that might override an extension's).I figured it might have to do with client hints that the extension isn't modifying or something to do with some Javascript navigator.stuff that the extension neglects to change., but not sure.
What does seem to work though is starting Opera like this:
"opera.exe" "--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36"
and not using an extension at all. Downside with that is it messes with Opera's sites.
-
burnout426 Volunteer last edited by
@escape75 said in Opera extensions fail to modify requestHeaders on google.com ...:
extension is installed that modifies the User-Agent header. For v2 extensions that use chrome.webRequest.onBeforeSendHeaders, as well as v3 extensions chrome.declarativeNetRequest via modifyHeaders, the extension is able to modify all requestHeaders as expected except headers on google.com domain, but the issue is only with the initial request, all subsequent modifications are fine.
Do you have minimal test extensions (v2 and v3) that show this?
-
escape75 last edited by
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.
-
burnout426 Volunteer last edited by
@escape75 Confirmed. Everything is correct with the extension and it works in other Chromium-based browsers. I filed DNA-116030 for it to see if it's a bug or something intentional Opera does for some reason.