Skip to content

Commit

Permalink
Important bugfix - adding webNavigation.onBeforeNavigate
Browse files Browse the repository at this point in the history
... which ensures that all cookies are cleared, before the navigation happens!
  • Loading branch information
jrie committed Jan 1, 2018
1 parent bd4fc93 commit 023305d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 17 deletions.
18 changes: 12 additions & 6 deletions cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ async function clearCookiesAction (action, data, cookies) {
}
}
}
} else if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal']['use'] === true) {
} else if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal'] === true) {
if (data[domainURL] === undefined) {
for (let cookie of cookies) {

if (hasProfile && hasLogged && data['flagCookies_logged'][domainURL][cookie.name] !== undefined) {
let msg = "Allowed profile cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
Expand Down Expand Up @@ -292,12 +291,17 @@ function chromeUpdateLogData (data, writeData) {
}
}

function clearCookiesOnNavigate (tabId, changeInfo, tab) {
if (changeInfo.status && changeInfo.status === 'loading') {
clearCookiesWrapper('tab reload/load', useChrome)
}
}

async function clearCookiesOnUpdate (tabId, changeInfo, tab) {

if (changeInfo.status && changeInfo.status === 'loading') {
clearDomainLog()
clearCookiesWrapper('tab reload/load', useChrome)
if (changeInfo['url'] === undefined) {
clearDomainLog();
}
} else if (changeInfo.status && changeInfo.status === 'complete') {
if (logData !== '') {
let urlMatch = tab.url.replace(/\/www\./, '/').match(/(http|https):\/\/[a-zA-Z0-9öäüÖÄÜ.-]*\//)
Expand Down Expand Up @@ -354,7 +358,7 @@ function clearDomainLog () {
}
}

function addToLogData (msg) {
async function addToLogData (msg) {
if (logData.indexOf(msg) === -1) logData.push(msg)
}

Expand All @@ -363,8 +367,10 @@ if (useChrome) {
chrome.tabs.onRemoved.addListener(clearCookiesOnLeave)
chrome.tabs.onUpdated.addListener(clearCookiesOnUpdate)
chrome.tabs.onActivated.addListener(setDomainURLOnActivation)
chrome.webNavigation.onBeforeNavigate.addListener(clearCookiesOnNavigate)
} else {
browser.tabs.onRemoved.addListener(clearCookiesOnLeave)
browser.tabs.onUpdated.addListener(clearCookiesOnUpdate)
browser.tabs.onActivated.addListener(setDomainURLOnActivation)
browser.webNavigation.onBeforeNavigate.addListener(clearCookiesOnNavigate)
}
20 changes: 10 additions & 10 deletions flagCookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ function updateUIData (data, cookies) {
document.getElementById('profileNoData').removeAttribute('class')
}

if (data['flagCookies_flagGlobal'] && data['flagCookies_flagGlobal']['use'] === true) {
if (data['flagCookies_flagGlobal'] && data['flagCookies_flagGlobal'] === true) {
flagGlobalAutoNonEvent()
}

Expand Down Expand Up @@ -359,7 +359,7 @@ async function flaggedCookieSwitchNeutral (data, event) {
// Uncheck from flagged in active cookies, if present
let domainCookieList = document.getElementById('cookie-list')
let hasAutoFlag = data['flagCookies_autoFlag'] !== undefined && data['flagCookies_autoFlag'][domainURL] !== undefined
let hasGlobal = data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal']['use'] === true
let hasGlobal = data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal'] === true

for (let child of domainCookieList.children) {
if (child.children[0].dataset['name'] === cookieName) {
Expand Down Expand Up @@ -417,7 +417,7 @@ async function permittedCookieSwitchNeutral (data, event) {
// Uncheck from permitted in active cookies, if present
let domainCookieList = document.getElementById('cookie-list')
let hasAutoFlag = data['flagCookies_autoFlag'] !== undefined && data['flagCookies_autoFlag'][domainURL] !== undefined
let hasGlobal = data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal']['use'] === true
let hasGlobal = data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal'] === true
for (let child of domainCookieList.children) {
if (child.children[0].dataset['name'] === cookieName) {
if (hasAutoFlag) {
Expand Down Expand Up @@ -498,7 +498,7 @@ async function cookieFlagSwitchNeutral (data, event) {
} else if (hasAutoFlag && data[domainURL][cookieName] !== 'af') {
data[domainURL][cookieName] = 'af'
event.target.className = 'checkmark auto-flagged'
} else if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal']['use'] !== undefined && data['flagCookies_flagGlobal']['use'] === true) {
} else if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal'] === true) {
delete data[domainURL][cookieName]
event.target.className = 'checkmark auto-flagged'
} else {
Expand Down Expand Up @@ -679,12 +679,12 @@ function flagGlobalAutoNonEventWrapper(data) {

if (globalFlagButton.className !== 'active') {
globalFlagButton.className = 'active'
data['flagCookies_flagGlobal']['use'] = true
data['flagCookies_flagGlobal'] = true
setChromeStorage(data)
switchAutoFlagGlobal(true, 'cookie-list')
} else {
globalFlagButton.removeAttribute('class')
data['flagCookies_flagGlobal']['use'] = false
data['flagCookies_flagGlobal'] = false
setChromeStorage(data)

let hasAutoFlag = data['flagCookies_autoFlag'] !== undefined && data['flagCookies_autoFlag'][domainURL] !== undefined
Expand Down Expand Up @@ -715,12 +715,12 @@ async function flagGlobalAutoNonEvent () {

if (globalFlagButton.className !== 'active') {
globalFlagButton.className = 'active'
data['flagCookies_flagGlobal']['use'] = true
data['flagCookies_flagGlobal'] = true
await browser.storage.local.set(data)
switchAutoFlagGlobal(true, 'cookie-list')
} else {
globalFlagButton.removeAttribute('class')
data['flagCookies_flagGlobal']['use'] = false
data['flagCookies_flagGlobal'] = false
await browser.storage.local.set(data)

let hasAutoFlag = data['flagCookies_autoFlag'] !== undefined ? data['flagCookies_autoFlag'][domainURL] !== undefined : false
Expand Down Expand Up @@ -782,7 +782,7 @@ async function switchAutoFlagNeutral(data, switchOn, targetList) {
if (data[domainURL][cookieKey] === 'af') {
delete data[domainURL][cookieKey]

if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal']['use'] !== true) {
if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal'] !== true) {
contentChild.className = 'checkmark'
}
}
Expand Down Expand Up @@ -958,7 +958,7 @@ async function resetUIDomain (data) {
let contentChild = child.children[0]
let contentChildProfile = child.children[2]

if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal']['use'] === true) {
if (data['flagCookies_flagGlobal'] !== undefined && data['flagCookies_flagGlobal'] === true) {
contentChild.className = 'checkmark auto-flagged'
} else {
contentChild.className = 'checkmark'
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"manifest_version": 2,
"name": "Flag Cookies",
"version": "1.6.1",
"permissions": ["cookies", "tabs", "<all_urls>", "storage", "unlimitedStorage"],
"permissions": ["cookies", "tabs", "webNavigation", "<all_urls>", "storage", "unlimitedStorage"],
"background": {
"scripts": [
"cookies.js"
Expand Down

0 comments on commit 023305d

Please sign in to comment.