From 255e0c04b2b471ebe1d06a5a30ccc93338d10f2b Mon Sep 17 00:00:00 2001
From: tophf <tophf@gmx.com>
Date: Thu, 28 Jan 2021 21:35:37 +0300
Subject: [PATCH] chrome bug: onCommitted is fired twice

---
 background/navigation-manager.js | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/background/navigation-manager.js b/background/navigation-manager.js
index dff9c6fe..1fa4a9f0 100644
--- a/background/navigation-manager.js
+++ b/background/navigation-manager.js
@@ -1,4 +1,4 @@
-/* global CHROME FIREFOX URLS ignoreChromeError */// toolbox.js
+/* global CHROME FIREFOX URLS deepEqual ignoreChromeError */// toolbox.js
 /* global bgReady */// common.js
 /* global msg */
 'use strict';
@@ -6,6 +6,7 @@
 /* exported navMan */
 const navMan = (() => {
   const listeners = new Set();
+  let prevData = {};
 
   chrome.webNavigation.onCommitted.addListener(onNavigation.bind('committed'));
   chrome.webNavigation.onHistoryStateUpdated.addListener(onFakeNavigation.bind('history'));
@@ -20,6 +21,10 @@ const navMan = (() => {
 
   /** @this {string} type */
   async function onNavigation(data) {
+    if (CHROME && data.timeStamp === prevData.timeStamp && deepEqual(data, prevData)) {
+      return; // Chrome bug: listener is called twice with identical data
+    }
+    prevData = data;
     if (CHROME &&
         URLS.chromeProtectsNTP &&
         data.url.startsWith('https://www.google.') &&