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

* fix: prevent title change for on page navigation

* add back and forward testing

* update Chromium comment

* remove errant script tag
This commit is contained in:
Michaela Laurencin 2025-03-14 07:10:23 -04:00 committed by GitHub
parent 7c0b7b417b
commit 4812b4e6c2
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', () => {