From 1d5f9ab28447fbc91abc06d337c62ed079ad42a2 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Tue, 29 Jun 2021 16:05:20 -0700 Subject: [PATCH 1/2] fix: correctly propagate title updates for window with no navigation entries --- shell/browser/api/electron_api_web_contents.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 99af573c47106..0d87bb155e92c 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -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); From db8d621ff5347f3e117f3a10eceac3b8401f84da Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Tue, 29 Jun 2021 16:40:43 -0700 Subject: [PATCH 2/2] test --- spec-main/api-web-contents-spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spec-main/api-web-contents-spec.ts b/spec-main/api-web-contents-spec.ts index a484de7d5e68d..3ecbaa50fad3c 100644 --- a/spec-main/api-web-contents-spec.ts +++ b/spec-main/api-web-contents-spec.ts @@ -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 });