fix: prevent title change for within page navigation (#46036)

* fix: prevent title change for on page navigation

Co-authored-by: Michaela Laurencin <mlaurencin@electronjs.org>

* add back and forward testing

Co-authored-by: Michaela Laurencin <mlaurencin@electronjs.org>

* update Chromium comment

Co-authored-by: Michaela Laurencin <mlaurencin@electronjs.org>

* remove errant script tag

Co-authored-by: Michaela Laurencin <mlaurencin@electronjs.org>

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Michaela Laurencin <mlaurencin@electronjs.org>
This commit is contained in:
trop[bot] 2025-03-14 11:01:31 -05:00 committed by GitHub
parent a1ec212049
commit c87fd357fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 9 deletions

View file

@ -631,6 +631,17 @@ describe('webContents module', () => {
w.webContents.navigationHistory.goBack();
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(0);
});
it('should have the same window title if navigating back within the page', async () => {
const title = 'Test';
w.webContents.on('did-finish-load', () => {
w.setTitle(title);
w.loadURL(`file://${fixturesPath}/pages/navigation-history-anchor-in-page.html#next`);
});
await w.loadURL(`file://${fixturesPath}/pages/navigation-history-anchor-in-page.html`);
w.webContents.navigationHistory.goBack();
expect(w.getTitle()).to.equal(title);
});
});
describe('navigationHistory.canGoForward and navigationHistory.goForward API', () => {
@ -653,6 +664,16 @@ describe('webContents module', () => {
w.webContents.navigationHistory.goForward();
expect(w.webContents.navigationHistory.getActiveIndex()).to.equal(1);
});
it('should have the same window title if navigating forward within the page', async () => {
const title = 'Test';
w.webContents.on('did-finish-load', () => {
w.setTitle(title);
w.loadURL(`file://${fixturesPath}/pages/navigation-history-anchor-in-page.html#next`);
});
await w.loadURL(`file://${fixturesPath}/pages/navigation-history-anchor-in-page.html`);
expect(w.getTitle()).to.equal(title);
});
});
describe('navigationHistory.canGoToOffset(index) and navigationHistory.goToOffset(index) API', () => {