diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 09c220c6e1cf..a45e166c92d3 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -439,6 +439,11 @@ content::WebContents* WebContents::OpenURLFromTab( if (Emit("will-navigate", params.url)) return nullptr; + // Don't load the URL if the web contents was marked as destroyed from a + // will-navigate event listener + if (IsDestroyed()) + return nullptr; + return CommonWebContentsDelegate::OpenURLFromTab(source, params); } diff --git a/atom/browser/api/trackable_object.h b/atom/browser/api/trackable_object.h index 3f04783bcd55..7ec544578869 100644 --- a/atom/browser/api/trackable_object.h +++ b/atom/browser/api/trackable_object.h @@ -65,6 +65,12 @@ class TrackableObject : public TrackableObjectBase, Wrappable::GetWrapper()->SetAlignedPointerInInternalField(0, nullptr); } + bool IsDestroyed() { + v8::Local wrapper = Wrappable::GetWrapper(); + return wrapper->InternalFieldCount() == 0 || + wrapper->GetAlignedPointerFromInternalField(0) == nullptr; + } + // Finds out the TrackableObject from its ID in weak map. static T* FromWeakMapID(v8::Isolate* isolate, int32_t id) { if (!weak_map_)