Skip to content

[Bug]: session.setUserAgent not inherited by iframes #40374

Closed as not planned
Closed as not planned

Description

@mayfield

Preflight Checklist

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.

Activity

  1. mayfield commented on Oct 31, 2023

    @mayfield
    ContributorAuthor

    Some additional data:

    All the WebContents instances look correct (i.e. they have "Electron" scrubbed from them in my case):

    electron.webContents.getAllWebContents().map(x => x.userAgent.match(/Electron/))
    (2) [null, null]
    
  2. jkleinsc commented on Oct 31, 2023

    @jkleinsc
    Member

    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.

  3. mayfield commented on Oct 31, 2023

    @mayfield
    ContributorAuthor

    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.

    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?

  4. mayfield commented on Nov 1, 2023

    @mayfield
    ContributorAuthor
  5. aguantelinux commented on May 31, 2024

    @aguantelinux

    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.

  6. jappp commented on Jul 31, 2024

    @jappp

    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

  7. Kai-GG commented on Oct 5, 2024

    @Kai-GG
    Contributor

    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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions