diff --git a/background.js b/background.js
index bf2f244f040e23b9594fb7f6aff6e19a34fb7e18..322e17d202d2fa13783fe242eeb8b2bc5e173617 100644
--- a/background.js
+++ b/background.js
@@ -109,7 +109,7 @@ function storeInBrowserStorage(item, callback_function) {
 function cookie_keyvalues_set(original_cookies, key, value) {
     let new_element = key + "=" + value; // not used if value is undefined. 
     let cookies_ar = original_cookies.split(";").filter(e => e.trim().length > 0);
-    let selected_cookie_index = cookies_ar.findIndex(kv => kv.startsWith(key+"="));
+    let selected_cookie_index = cookies_ar.findIndex(kv => kv.trim().startsWith(key+"="));
     if (selected_cookie_index == -1)
         cookies_ar.push(new_element);
     else {