let cookieName = 'XDEBUG_SESSION';
let currentTab;

async function updateIcon() {
    let cookie = await getCookie();
    let icons = await getIcons(cookie);

    browser.browserAction.setIcon({
        path: icons,
        tabId: currentTab.id
    });
    browser.browserAction.setTitle({
        title: cookie ? 'xDEBUG Session (on)' : 'xDEBUG Session (off)',
        tabId: currentTab.id
    });
}

async function toggleCookie() {
    let cookie = await getCookie();

    if (cookie) {
        browser.cookies.remove({
            url: currentTab.url,
            name: cookieName
        });
        updateIcon();
        return null;
    }

    let config = await browser.storage.sync.get('xdebug_session');

    browser.cookies.set({
        url: currentTab.url,
        name: cookieName,
        value: config.xdebug_session || 'phpstorm',
        path: "/"
    });
    updateIcon();
}

async function getIcons(cookie) {
    let state = 'xdebug_session_off_color';
    let stateColor = 'light';
    if (cookie) {
        state = 'xdebug_session_on_color';
        stateColor = 'red';
    }
    let config = await browser.storage.sync.get(state);
    if (config[state]) {
        stateColor = config[state];
    }

    return {
        "64": "icons/bug-"+ stateColor +"-64.png",
        "128": "icons/bug-"+ stateColor +"-128.png"
    }
}

async function getCookie() {
    return browser.cookies.get({
        url: currentTab.url,
        name: cookieName
    });
}

async function updateActiveTab() {
    function updateTab(tabs) {
        if (tabs[0]) {
            currentTab = tabs[0];
            updateIcon();
        }
    }

    let tabs = await browser.tabs.query({active: true, currentWindow: true});
    updateTab(tabs);
}

updateActiveTab();

browser.browserAction.onClicked.addListener(toggleCookie);
browser.tabs.onUpdated.addListener(updateActiveTab);
browser.tabs.onActivated.addListener(updateActiveTab);
browser.windows.onFocusChanged.addListener(updateActiveTab);


@@ -538,32 +538,63 @@
 : currentTab.url
+.replace(/:%7B1%7D%5B0-9%5D%7B1%7D%5Cd*/, '')
 ,%0A            na
@@ -1276,32 +1276,33 @@
 4%22: %22icons/bug-%22
+ 
 + stateColor +%22-
@@ -1299,16 +1299,17 @@
 eColor +
+ 
 %22-64.png
@@ -1338,16 +1338,17 @@
 ns/bug-%22
+ 
 + stateC
@@ -1353,16 +1353,17 @@
 eColor +
+ 
 %22-128.pn
@@ -1455,32 +1455,63 @@
 : currentTab.url
+.replace(/:%7B1%7D%5B0-9%5D%7B1%7D%5Cd*/, '')
 ,%0A        name: 

Fix searching for cookies when address has port