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

fix: empty result of webContents.getUserAgent()
This commit is contained in:
Shelley Vohr 2022-07-29 17:09:47 +02:00 committed by GitHub
parent 8004cb8722
commit 9028bb79a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 14 deletions

View file

@ -675,10 +675,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));
@ -884,10 +882,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;

View file

@ -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_ =

View file

@ -89,7 +89,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();

View file

@ -902,6 +902,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();