You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: session.setUserAgent not inherited by iframes #40374
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for a bug report that matches the one I want to file, without success.
Electron Version
24
What operating system are you using?
Other Linux
Operating System Version
NA
What arch are you using?
x64
Last Known Working Electron version
No response
Expected Behavior
For any context of a BrowserWindow using a custom session to use the session based user-agent.
Actual Behavior
The top frame uses the correct session based user agent but iframes of the same window do not.
Testcase Gist URL
No response
Additional Information
Repro:
session = electron.session.fromPartition('persist:foobar');
session.setUserAgent('CUSTOM');
win = new electron.BrowserWindow({webPreferences: {session}});
win.loadURL('some site with iframes');
// Observe the incorrect user-agent header being used for the iframes (in my case I remove Electron and my product name from useragent to prevent anti-bot issues)
window-25.mp4
It appears this affects new popup windows too, but that's perhaps for another report.
Hello, I've encountered the same issue in [email protected]. The problem manifests when I customize the useragent parameter for the webview tag. It works as expected for page A, which is loaded directly through the webview. However, if page A includes an iframe that loads page B, the user agent for HTTP requests initiated by page B reverts to the default Electron UA.Do you have any good suggestions? @jkleinsc
Hello, I've encountered the same issue in [email protected]. The problem manifests when I customize the useragent parameter for the webview tag. It works as expected for page A, which is loaded directly through the webview. However, if page A includes an iframe that loads page B, the user agent for HTTP requests initiated by page B reverts to the default Electron UA.Do you have any good suggestions? @jkleinsc
You can use webRequest.onBeforeSendHeaders to solve the issue with the request headers
Activity
mayfield commentedon Oct 31, 2023
Some additional data:
All the WebContents instances look correct (i.e. they have "Electron" scrubbed from them in my case):
jkleinsc commentedon Oct 31, 2023
Thank you for reaching out!
The version of Electron reported in this issue has reached end-of-life and is no longer supported, so this issue will be closed.
If you're still experiencing this issue on a supported version of Electron, please file a new issue for that version of Electron.
Thanks in advance! Your help is appreciated.
mayfield commentedon Oct 31, 2023
Hi I really don't want to re-enter all of this info but this bug is still present on 27 (just tested). Can you reopen?
mayfield commentedon Nov 1, 2023
@jkleinsc
aguantelinux commentedon May 31, 2024
I have the same issue in [email protected]. When using
electronSession.webRequest.onBeforeSendHeaders((details, callback) => {
details.requestHeaders['User-Agent'] = user_Agent;
callback({ cancel: false, requestHeaders: details.requestHeaders });
});
it works well for everything except those that are inside an iframe.
jappp commentedon Jul 31, 2024
Hello, I've encountered the same issue in [email protected]. The problem manifests when I customize the useragent parameter for the webview tag. It works as expected for page A, which is loaded directly through the webview. However, if page A includes an iframe that loads page B, the user agent for HTTP requests initiated by page B reverts to the default Electron UA.Do you have any good suggestions?
@jkleinsc
Kai-GG commentedon Oct 5, 2024
You can use webRequest.onBeforeSendHeaders to solve the issue with the request headers