From aec307d9d697596992ef8f1c21b1589bd8ee6213 Mon Sep 17 00:00:00 2001 From: Kudlaty Date: Sun, 6 Jan 2019 22:11:07 +0100 Subject: [PATCH] Make it work in private window and containers --- manifest.json | 2 +- xdebug.js | 38 ++++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/manifest.json b/manifest.json index 0eee41a..8c07be1 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Xdebug Session Cookie", - "version": "1.1", + "version": "1.2", "description": "Adds cookie that enables XDEBUG SESSION for php xdebug.", "homepage_url": "https://github.com/kudlatyamroth/xdebug-session-cookie", diff --git a/xdebug.js b/xdebug.js index 3b581fe..db1f255 100644 --- a/xdebug.js +++ b/xdebug.js @@ -17,23 +17,25 @@ async function updateIcon() { async function toggleCookie() { let cookie = await getCookie(); + let currentUrl = currentTab.url; if (cookie) { browser.cookies.remove({ - url: currentTab.url.replace(/:{1}[0-9]{1}\d*/, ''), - name: cookieName + url: currentUrl.replace(/:{1}[0-9]{1}\d*/, ''), + name: cookieName, + storeId: currentTab.cookieStoreId }); updateIcon(); return null; } - let config = await browser.storage.sync.get('xdebug_session'); - + let valueToSet = await getValueToSet(); browser.cookies.set({ - url: currentTab.url, + url: currentUrl.replace(/:{1}[0-9]{1}\d*/, ''), name: cookieName, - value: config.xdebug_session || 'phpstorm', - path: "/" + value: valueToSet, + path: "/", + storeId: currentTab.cookieStoreId }); updateIcon(); } @@ -56,11 +58,27 @@ async function getIcons(cookie) { } } +async function getValueToSet() { + let config = await browser.storage.sync.get('xdebug_session'); + + return config.xdebug_session || 'phpstorm'; +} + async function getCookie() { - return browser.cookies.get({ - url: currentTab.url.replace(/:{1}[0-9]{1}\d*/, ''), - name: cookieName + let currentUrl = currentTab.url; + let valueToSet = await getValueToSet(); + + let cookie = await browser.cookies.get({ + url: currentUrl.replace(/:{1}[0-9]{1}\d*/, ''), + name: cookieName, + storeId: currentTab.cookieStoreId }); + + if (cookie && cookie.value == valueToSet) { + return cookie; + } + + return null; } async function updateActiveTab() {