Skip to content

Commit

Permalink
fix: correctly propagate title updates for window with no navigation …
Browse files Browse the repository at this point in the history
…entries (#29960)

* fix: correctly propagate title updates for window with no navigation entries

* test

Co-authored-by: Jeremy Rose <nornagon@nornagon.net>
  • Loading branch information
trop[bot] and nornagon committed Jul 2, 2021
1 parent 545aba8 commit 85e4bff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -1740,6 +1740,8 @@ void WebContents::TitleWasSet(content::NavigationEntry* entry) {
} else {
final_title = title;
}
} else {
final_title = web_contents()->GetTitle();
}
for (ExtendedWebContentsObserver& observer : observers_)
observer.OnPageTitleUpdated(final_title, explicit_set);
Expand Down
13 changes: 13 additions & 0 deletions spec-main/api-web-contents-spec.ts
Expand Up @@ -1999,6 +1999,19 @@ describe('webContents module', () => {
});
});

describe('page-title-updated event', () => {
afterEach(closeAllWindows);
it('is emitted with a full title for pages with no navigation', async () => {
const bw = new BrowserWindow({ show: false, webPreferences: { nativeWindowOpen: true } });
await bw.loadURL('about:blank');
bw.webContents.executeJavaScript('child = window.open("", "", "show=no"); null');
const [, child] = await emittedOnce(app, 'web-contents-created');
bw.webContents.executeJavaScript('child.document.title = "new title"');
const [, title] = await emittedOnce(child, 'page-title-updated');
expect(title).to.equal('new title');
});
});

describe('crashed event', () => {
it('does not crash main process when destroying WebContents in it', (done) => {
const contents = (webContents as any).create({ nodeIntegration: true });
Expand Down

0 comments on commit 85e4bff

Please sign in to comment.