From fea59c5601252e1452369592f7f4707039af7d90 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 2 Jul 2021 09:49:58 +0900 Subject: [PATCH] fix: correctly propagate title updates for window with no navigation entries (#29958) * fix: correctly propagate title updates for window with no navigation entries * test Co-authored-by: Jeremy Rose --- shell/browser/api/electron_api_web_contents.cc | 2 ++ spec-main/api-web-contents-spec.ts | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 5c3ce8999bb66..2dcc2eec0006d 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1733,6 +1733,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); diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index 058af2649fa80..240c3a41e696b 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -1996,6 +1996,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 });