Skip to content

fix: make ServiceWorkers respect the session-wide User Agent override - #17650

Closed
MarshallOfSound wants to merge 3 commits into
masterfrom
fix-service-worker-user-agent
Closed

MarshallOfSound wants to merge 3 commits into
masterfrom
fix-service-worker-user-agent

Conversation

@MarshallOfSound

Copy link
Copy Markdown
Member

Description of Change

This adds a patch that exposes our GetUserAgent API on content::BrowserContext and then safely tries to fetch it during service worker initialization. If no override has been set it falls back to the original technique.

Fixes #16196

Release Notes

Notes: Fixed issue where session.setUserAgent did not override the user agent for service workers.

@MarshallOfSound
MarshallOfSound requested a review from a team as a code owner April 2, 2019 01:42
@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Apr 2, 2019

@deepak1556 deepak1556 left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if ContentBrowserClient::GetUserAgent passed the browser context as a parameter, that way we can return session specific agent with lesser patch. Also this style mimics the ContentBrowserClient::CreateNetworkContext api and we can upstream it too.

@MarshallOfSound
MarshallOfSound force-pushed the fix-service-worker-user-agent branch from c884d8a to 06b1b59 Compare April 2, 2019 20:05
@MarshallOfSound

Copy link
Copy Markdown
Member Author

Following discussions with @deepak1556 I've updated the patch to be much more upstreamable. It is now slightly larger but we should be able to upstream and remove 👍

@nornagon nornagon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable to me; I'd recommend opening a CL upstream to get feedback there before merging (though that wouldn't necessarily block this from landing)

@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Apr 3, 2019

@deepak1556 deepak1556 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for landing, agree with @nornagon on getting feedback from upstream.

params->script_url = script_url_;
params->script_type = script_type_;
- params->user_agent = GetContentClient()->browser()->GetUserAgent();
+ params->user_agent = context_->process_manager()->GetUserAgent(GetContentClient()->browser());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetContentClient()->browser() can be accessed directly in ServiceWorkerProcessManager, since its a per process variable. Pass it as an argument isn't the usual style :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deepak1556 That's what I thought but the thing failed to build when I tried to use it directly. I'll try again when I try to upstream

@MarshallOfSound

Copy link
Copy Markdown
Member Author

Upstream CL: https://chromium-review.googlesource.com/c/chromium/src/+/1552100

@deepak1556

Copy link
Copy Markdown
Member

For the code path that sets useragent on network context params, its sufficient to pass nullptr as argument, since in chromium we create a default app level network context and also per context level network context. But lets see what the upstream team suggests :)

@HaNdTriX

Copy link
Copy Markdown

@MarshallOfSound just wanted to say thank you so much for taking a shot at this 🙏!
Is there anything I can help you with to get this merged?

@MarshallOfSound

Copy link
Copy Markdown
Member Author

Closing due to the new app.userAgentOverride feature

@MarshallOfSound
MarshallOfSound deleted the fix-service-worker-user-agent branch June 24, 2019 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can't set userAgent in serviceWorker

4 participants