From c740ace3ccc69f0b1400545eec154df255bfca8b Mon Sep 17 00:00:00 2001 From: Anya Mallon Date: Wed, 9 Aug 2023 10:21:18 +0200 Subject: [PATCH 1/3] Change behaviour so that only current tab (that triggered the incontext prompt) is the one that responds to the incontext notifications --- DuckDuckGo/Tab/View/BrowserTabViewController.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/DuckDuckGo/Tab/View/BrowserTabViewController.swift b/DuckDuckGo/Tab/View/BrowserTabViewController.swift index 52d800159e..d79476e763 100644 --- a/DuckDuckGo/Tab/View/BrowserTabViewController.swift +++ b/DuckDuckGo/Tab/View/BrowserTabViewController.swift @@ -124,6 +124,9 @@ final class BrowserTabViewController: NSViewController { @objc private func onDuckDuckGoEmailIncontextSignup(_ notification: Notification) { + guard tabCollectionViewModel.selectedTab == WindowControllersManager.shared.selectedTab else { + return + } self.previouslySelectedTab = tabCollectionViewModel.selectedTab let tab = Tab(content: .url(EmailUrls().emailProtectionInContextSignupLink), shouldLoadInBackground: true) tabCollectionViewModel.append(tab: tab) @@ -131,6 +134,9 @@ final class BrowserTabViewController: NSViewController { @objc private func onCloseDuckDuckGoEmailProtection(_ notification: Notification) { + guard tabCollectionViewModel.selectedTab == WindowControllersManager.shared.selectedTab else { + return + } guard let activeTab = tabCollectionViewModel.selectedTabViewModel?.tab else { return } if activeTab.url != nil && EmailUrls().isDuckDuckGoEmailProtection(url: activeTab.url!) { self.closeTab(activeTab) From 4471af8a0e7407a44aabac991c00af794c3170b0 Mon Sep 17 00:00:00 2001 From: Anya Mallon Date: Wed, 9 Aug 2023 11:04:01 +0200 Subject: [PATCH 2/3] Changing incontext url to load in foreground in case timing issue is causing browser detection to fail --- DuckDuckGo/Tab/View/BrowserTabViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DuckDuckGo/Tab/View/BrowserTabViewController.swift b/DuckDuckGo/Tab/View/BrowserTabViewController.swift index d79476e763..f7159084c9 100644 --- a/DuckDuckGo/Tab/View/BrowserTabViewController.swift +++ b/DuckDuckGo/Tab/View/BrowserTabViewController.swift @@ -128,7 +128,7 @@ final class BrowserTabViewController: NSViewController { return } self.previouslySelectedTab = tabCollectionViewModel.selectedTab - let tab = Tab(content: .url(EmailUrls().emailProtectionInContextSignupLink), shouldLoadInBackground: true) + let tab = Tab(content: .url(EmailUrls().emailProtectionInContextSignupLink), shouldLoadInBackground: false) tabCollectionViewModel.append(tab: tab) } From b40268c31751ee72ee48ce12eec05ca69a21b7e5 Mon Sep 17 00:00:00 2001 From: Anya Mallon Date: Thu, 10 Aug 2023 13:12:18 +0200 Subject: [PATCH 3/3] Adding logging --- DuckDuckGo/Tab/View/BrowserTabViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/DuckDuckGo/Tab/View/BrowserTabViewController.swift b/DuckDuckGo/Tab/View/BrowserTabViewController.swift index f7159084c9..a3fe641977 100644 --- a/DuckDuckGo/Tab/View/BrowserTabViewController.swift +++ b/DuckDuckGo/Tab/View/BrowserTabViewController.swift @@ -144,6 +144,7 @@ final class BrowserTabViewController: NSViewController { if let previouslySelectedTab = self.previouslySelectedTab { tabCollectionViewModel.select(tab: previouslySelectedTab) if #available(macOS 11.0, *) { + os_log(.debug, "Tab %{private}s calling openAutofillAfterClosingEmailProtectionTab()", previouslySelectedTab.webView.url?.absoluteString ?? "with no url") previouslySelectedTab.webView.evaluateJavaScript("window.openAutofillAfterClosingEmailProtectionTab()", in: nil, in: WKContentWorld.defaultClient) } self.previouslySelectedTab = nil