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
Network requests made from service worker context don't have electron app name and version in the User Agent header #19600
I agree to follow the Code of Conduct that this project adheres to.
I have searched the issue tracker for an issue that matches the one I want to file, without success.
Issue Details
Electron Version:
3.1.13
Operating System:
Windows 10.0.18632
Last Known Working Electron version:
Not sure if it ever worked
Expected Behavior
The user agent string for network requests made from Electron contain the Electron app name and version. For example:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) electron-quick-start/1.0.0 Chrome/66.0.3359.181 Electron/3.1.13 Safari/537.36
The user agent should contain the "electron-quick-start/1.0.0" string irrespective of whether the requests are made from main window or service worker context. Many modern applications have a service worker which makes/intercepts most network requests to improve performance and make the app work offline. We should have the user agent with Electron app name from both contexts.
Actual Behavior
But network requests made from service worker context don't append the Electron app name and version to the user agent string. It does not contain the "electron-quick-start/1.0.0". For example:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Electron/3.1.13 Safari/537.36
We are not customizing the user agent here and want to use the default user agent string. If the user agent has been modified in Electron to include the Electron app name and version for requests made from the main thread in renderer process, I would expect that the requests made from service worker thread also to have the same user agent. There are a lot of scenarios where user agent header is used on the server side to detect versions of app/electron/browser and serve different content. Having a different user agent by default for requests made from service worker and main threads seems like a bug to me.
Thanks for the quick response. I verified that this issue does not exist in 4.x.x and above. In general, is there any documentation around how service workers are implemented under the hood in Electron. We are seeing other issues like increased crash rate in Mac OS X etc. and would like to learn more.
Additional note: Looks like customizing the user agent using app.userAgentFallback and other options does not work in service worker context based on this issue #16196
is there any documentation around how service workers are implemented under the hood in Electron
Service workers in Electron aren't "implemented" really at all, that all comes from Chromium upstream, we don't do anything special to support it, they Just Work ™️
There is no way to specify the user agent for service workers in 4.x and 5.x?
4.2.x supports app.userAgentFallback. 5.x does not. We can't backport to 5.x without a semver minor bump and we have no intention to do that at this time.
4.x and 6.x are both stable releases so you should be able to use one of them (preferably 6)
Activity
MarshallOfSound commentedon Aug 2, 2019
Service workers run in a different renderer host under the hood. If you want to adjust the user agent you should use
app.userAgentFallbacksreedhar7 commentedon Aug 2, 2019
We are not customizing the user agent here and want to use the default user agent string. If the user agent has been modified in Electron to include the Electron app name and version for requests made from the main thread in renderer process, I would expect that the requests made from service worker thread also to have the same user agent. There are a lot of scenarios where user agent header is used on the server side to detect versions of app/electron/browser and serve different content. Having a different user agent by default for requests made from service worker and main threads seems like a bug to me.
MarshallOfSound commentedon Aug 2, 2019
Oh I didn't check your electron version
(a)
3.1.13is EOL and you should upgrade(b) this is fixed in the most recent versions of Electron 👍
sreedhar7 commentedon Aug 2, 2019
Thanks for the quick response. I verified that this issue does not exist in 4.x.x and above. In general, is there any documentation around how service workers are implemented under the hood in Electron. We are seeing other issues like increased crash rate in Mac OS X etc. and would like to learn more.
sreedhar7 commentedon Aug 2, 2019
Additional note: Looks like customizing the user agent using app.userAgentFallback and other options does not work in service worker context based on this issue #16196
MarshallOfSound commentedon Aug 2, 2019
@sreedhar7 That issue is wrong 😄
app.userAgentFallbackis a very new feature and those folks probably weren't on a new enough version of electron.I know for sure that
app.userAgentFallbackworks for service workers 👍MarshallOfSound commentedon Aug 2, 2019
Service workers in Electron aren't "implemented" really at all, that all comes from Chromium upstream, we don't do anything special to support it, they Just Work ™️
bughit commentedon Aug 7, 2019
@MarshallOfSound
MarshallOfSound commentedon Aug 7, 2019
4.2.xsupportsapp.userAgentFallback.5.xdoes not. We can't backport to5.xwithout a semver minor bump and we have no intention to do that at this time.4.xand6.xare both stable releases so you should be able to use one of them (preferably 6)