Fix "Object has been destroyed" error in "page-title-updated" event
Close #4249.
This commit is contained in:
parent
899294a040
commit
5d16257c2d
1 changed files with 10 additions and 8 deletions
|
@ -55,14 +55,16 @@ BrowserWindow.prototype._init = function() {
|
||||||
})(this));
|
})(this));
|
||||||
|
|
||||||
// Change window title to page title.
|
// Change window title to page title.
|
||||||
this.webContents.on('page-title-updated', (function(_this) {
|
this.webContents.on('page-title-updated', (event, title) => {
|
||||||
return function(event, title) {
|
// The page-title-updated event is not emitted immediately (see #3645), so
|
||||||
_this.emit('page-title-updated', event, title);
|
// when the callback is called the BrowserWindow might have been closed.
|
||||||
if (!event.defaultPrevented) {
|
if (this.isDestroyed())
|
||||||
return _this.setTitle(title);
|
return;
|
||||||
}
|
// Route the event to BrowserWindow.
|
||||||
};
|
this.emit('page-title-updated', event, title);
|
||||||
})(this));
|
if (!event.defaultPrevented)
|
||||||
|
this.setTitle(title);
|
||||||
|
});
|
||||||
|
|
||||||
// Sometimes the webContents doesn't get focus when window is shown, so we have
|
// Sometimes the webContents doesn't get focus when window is shown, so we have
|
||||||
// to force focusing on webContents in this case. The safest way is to focus it
|
// to force focusing on webContents in this case. The safest way is to focus it
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue