Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: empty result of webContents.getUserAgent() #35130

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -661,10 +661,8 @@ WebContents::WebContents(v8::Isolate* isolate,
auto session = Session::CreateFrom(isolate, GetBrowserContext());
session_.Reset(isolate, session.ToV8());

absl::optional<std::string> user_agent_override =
GetBrowserContext()->GetUserAgentOverride();
if (user_agent_override)
SetUserAgent(*user_agent_override);
SetUserAgent(GetBrowserContext()->GetUserAgent());

web_contents->SetUserData(kElectronApiWebContentsKey,
std::make_unique<UserDataLink>(GetWeakPtr()));
InitZoomController(web_contents, gin::Dictionary::CreateEmpty(isolate));
Expand Down Expand Up @@ -870,10 +868,7 @@ void WebContents::InitWithSessionAndOptions(

AutofillDriverFactory::CreateForWebContents(web_contents());

absl::optional<std::string> user_agent_override =
GetBrowserContext()->GetUserAgentOverride();
if (user_agent_override)
SetUserAgent(*user_agent_override);
SetUserAgent(GetBrowserContext()->GetUserAgent());

if (IsGuest()) {
NativeWindow* owner_window = nullptr;
Expand Down
5 changes: 0 additions & 5 deletions shell/browser/electron_browser_context.cc
Expand Up @@ -308,11 +308,6 @@ std::string ElectronBrowserContext::GetUserAgent() const {
return user_agent_.value_or(ElectronBrowserClient::Get()->GetUserAgent());
}

absl::optional<std::string> ElectronBrowserContext::GetUserAgentOverride()
const {
return user_agent_;
}

predictors::PreconnectManager* ElectronBrowserContext::GetPreconnectManager() {
if (!preconnect_manager_.get()) {
preconnect_manager_ =
Expand Down
1 change: 0 additions & 1 deletion shell/browser/electron_browser_context.h
Expand Up @@ -85,7 +85,6 @@ class ElectronBrowserContext : public content::BrowserContext {

void SetUserAgent(const std::string& user_agent);
std::string GetUserAgent() const;
absl::optional<std::string> GetUserAgentOverride() const;
bool CanUseHttpCache() const;
int GetMaxCacheSize() const;
ResolveProxyHelper* GetResolveProxyHelper();
Expand Down
6 changes: 6 additions & 0 deletions spec-main/api-web-contents-spec.ts
Expand Up @@ -901,6 +901,12 @@ describe('webContents module', () => {
});

describe('userAgent APIs', () => {
it('is not empty by default', () => {
const w = new BrowserWindow({ show: false });
const userAgent = w.webContents.getUserAgent();
expect(userAgent).to.be.a('string').that.is.not.empty();
});

it('can set the user agent (functions)', () => {
const w = new BrowserWindow({ show: false });
const userAgent = w.webContents.getUserAgent();
Expand Down