Skip to content

Can't set userAgent in serviceWorker #16196

Closed

Description

@HaNdTriX
  • Output of node_modules/.bin/electron --version: v4.0.0
  • Output of node_modules/.bin/electron --version: v5.0.0-beta.5
  • Operating System (Platform and Version): MacOS 10.14.2
  • Operating System (Platform and Version): Windows 10

Expected Behavior

The userAgent of a serviceworker context should be settable.
None of the following methods work:

  • session.setUserAgent('foo')
  • <webview useragent='foo' />
  • win.loadURL(..,{ userAgent: 'foo'})
  • webRequest.onBeforeSendHeaders([filter, ]listener)

Actual behavior

Currently the userAgent of serviceworkers used in an electron app ist not settable.

To Reproduce

Check out the following example:
https://github.com/HaNdTriX/service-worker-user-agent-electron-bug-

If you provide a URL, please list the commands required to clone/setup/run your repo e.g.

$ git clone [email protected]:HaNdTriX/service-worker-user-agent-electron-bug-.git
$ npm install
$ npm start

Then reload the renderer once to see the value of navigator.userAgent

Activity

  1. LuKks commented on Feb 15, 2019

    @LuKks

    Neither modifying the headers, at least my tries.

    I don't want to expose that I'm using Electron, so it would be enough for me not add "Electron/Version".

    Would be great if there were something like disable the "powered by".
    I tried search inside of the Electron files but I don't really see where the modification occurs.

    The second one is made by the service worker.
    GitHub Logo

  2. HaNdTriX commented on Mar 11, 2019

    @HaNdTriX
    Author

    @sofianguy I just tested [email protected] and the bug is also present here.
    Can you add the corresponding tag (5-0-x) as well?

    Thanks!

  3. grgvineet commented on Jul 15, 2019

    @grgvineet

    Still not able to set user agent for service worker request. Using following code to set user agent
    app.userAgentFallback = "Custom user agent";

    But getting following user agent in service worker requests.
    User-Agent: Chrome/69.0.3497.128 Electron/4.2.6

  4. HaNdTriX commented on Sep 20, 2019

    @HaNdTriX
    Author

    Just for info you can now use the new app.userAgentOverride to work around this issue:
    #17650

  5. electron-triage commented on Feb 19, 2020

    @electron-triage

    Thank you for taking the time to report this issue and helping to make Electron better.

    The version of Electron you reported this on has been superseded by newer releases.

    If you're still experiencing this issue in Electron 6.x.y or later, please add a comment specifying the version you're testing with and any other new information that a maintainer trying to reproduce the issue should know.

    I'm setting the blocked/need-info label for the above reasons. This issue will be closed 7 days from now if there is no response.

    Thanks in advance! Your help is appreciated.

  6. added
    blocked/need-info ❌
    on Feb 19, 2020
  7. electron-triage commented on Feb 26, 2020

    @electron-triage

    Thank you for your issue!

    We haven't gotten a response to our questions in our comment above. With only the information that is currently in the issue, we don't have enough information to take action. I'm going to close this but don't hesitate to reach out if you have or find the answers we need, we'll be happy to reopen the issue.

  8. stewartlord commented on Feb 26, 2020

    @stewartlord
    Contributor

    Edit: the workaround is to set app.userAgentFallback (not app.userAgentOverride)

  9. sputnikW commented on Jan 8, 2024

    @sputnikW

    Still not able to set user agent for service worker request. Using following code to set user agent app.userAgentFallback = "Custom user agent";

    But getting following user agent in service worker requests. User-Agent: Chrome/69.0.3497.128 Electron/4.2.6

    I found that if you set userAgentFallback after ready event of app, the useragent is not work for serviceworker request .
    You can set userAgentFallback before ready event, like in the entry file.

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

    4-2-x5-0-xblocked/need-info ❌bug 🪲platform/macOS

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions