fix: set userAgent
on navigationHistory.restore()
(#46300)
fix: set userAgent on navigationHistory restore Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
parent
f9164968d6
commit
fe445869ca
2 changed files with 32 additions and 0 deletions
|
@ -2624,6 +2624,9 @@ void WebContents::RestoreHistory(
|
||||||
auto navigation_entries = std::make_unique<
|
auto navigation_entries = std::make_unique<
|
||||||
std::vector<std::unique_ptr<content::NavigationEntry>>>();
|
std::vector<std::unique_ptr<content::NavigationEntry>>>();
|
||||||
|
|
||||||
|
blink::UserAgentOverride ua_override;
|
||||||
|
ua_override.ua_string_override = GetUserAgent();
|
||||||
|
|
||||||
for (const auto& entry : entries) {
|
for (const auto& entry : entries) {
|
||||||
content::NavigationEntry* nav_entry = nullptr;
|
content::NavigationEntry* nav_entry = nullptr;
|
||||||
if (!gin::Converter<content::NavigationEntry*>::FromV8(isolate, entry,
|
if (!gin::Converter<content::NavigationEntry*>::FromV8(isolate, entry,
|
||||||
|
@ -2636,11 +2639,15 @@ void WebContents::RestoreHistory(
|
||||||
std::to_string(index) + ".");
|
std::to_string(index) + ".");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nav_entry->SetIsOverridingUserAgent(
|
||||||
|
!ua_override.ua_string_override.empty());
|
||||||
navigation_entries->push_back(
|
navigation_entries->push_back(
|
||||||
std::unique_ptr<content::NavigationEntry>(nav_entry));
|
std::unique_ptr<content::NavigationEntry>(nav_entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!navigation_entries->empty()) {
|
if (!navigation_entries->empty()) {
|
||||||
|
web_contents()->SetUserAgentOverride(ua_override, false);
|
||||||
web_contents()->GetController().Restore(
|
web_contents()->GetController().Restore(
|
||||||
index, content::RestoreType::kRestored, navigation_entries.get());
|
index, content::RestoreType::kRestored, navigation_entries.get());
|
||||||
web_contents()->GetController().LoadIfNecessary();
|
web_contents()->GetController().LoadIfNecessary();
|
||||||
|
|
|
@ -887,6 +887,31 @@ describe('webContents module', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should restore an overridden user agent', async () => {
|
||||||
|
const partition = 'persist:wcvtest';
|
||||||
|
const testUA = 'MyCustomUA';
|
||||||
|
|
||||||
|
const ses = session.fromPartition(partition);
|
||||||
|
ses.setUserAgent(testUA);
|
||||||
|
|
||||||
|
const wcv = new WebContentsView({
|
||||||
|
webPreferences: { partition }
|
||||||
|
});
|
||||||
|
|
||||||
|
wcv.webContents.navigationHistory.restore({
|
||||||
|
entries: [{
|
||||||
|
url: urlPage1,
|
||||||
|
title: 'url1'
|
||||||
|
}],
|
||||||
|
index: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
const ua = wcv.webContents.getUserAgent();
|
||||||
|
const wcvua = await wcv.webContents.executeJavaScript('navigator.userAgent');
|
||||||
|
|
||||||
|
expect(ua).to.equal(wcvua);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getFocusedWebContents() API', () => {
|
describe('getFocusedWebContents() API', () => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue