Skip to content

Commit

Permalink
Add important log console dectection
Browse files Browse the repository at this point in the history
.. without a check if a developer console was openend, the add seemed to cease working in Chrome
  • Loading branch information
jrie committed Dec 31, 2017
1 parent 3925980 commit bd4fc93
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 40 deletions.
55 changes: 29 additions & 26 deletions cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ let logData = [] // The log data we seen as a report to the settings view

// Chrome
let useChrome = typeof (browser) === 'undefined'
let hasConsole = typeof (console) !== 'undefined'

// Chrome helpers
function checkChromeHadNoErrors () {
if (chrome.runtime.lastError) {
if (chrome.runtime.lastError.message !== undefined) {
console.log('Chrome had an error, with mesage: ' + chrome.runtime.lastError.message)
} else {
console.log('Chrome had an error.')
if (hasConsole) {
if (chrome.runtime.lastError.message !== undefined) {
console.log('Chrome had an error, with mesage: ' + chrome.runtime.lastError.message)
} else {
console.log('Chrome had an error.')
}
}

void chrome.runtime.lastError
Expand Down Expand Up @@ -69,14 +72,14 @@ async function clearCookiesAction (action, data, 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)
console.log(msg)
if (hasConsole) console.log(msg)
continue
}

if (data[domainURL][cookie.name] === false) {
let msg = "Permitted cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
continue
}

Expand All @@ -89,11 +92,11 @@ async function clearCookiesAction (action, data, cookies) {
if (data[domainURL][cookie.name] === true) {
let msg = "Deleted on '" + action + "', cookie: '" + cookieName + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
} else {
let msg = "Auto-flag deleted on '" + action + "', cookie: '" + cookieName + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}
}

Expand All @@ -104,11 +107,11 @@ async function clearCookiesAction (action, data, cookies) {
if (data[domainURL][cookie.name] === true) {
let msg = "Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
} else {
let msg = "Auto-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}
}
}
Expand All @@ -119,7 +122,7 @@ async function clearCookiesAction (action, data, 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)
console.log(msg)
if (hasConsole) console.log(msg)
continue
}

Expand All @@ -130,7 +133,7 @@ async function clearCookiesAction (action, data, cookies) {
if (chrome.cookies.remove(details) !== null) {
let msg = "Global-flag deleted on '" + action + "', cookie: '" +cookieName + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}

continue
Expand All @@ -139,22 +142,22 @@ async function clearCookiesAction (action, data, cookies) {
if ((await browser.cookies.remove(details)) !== null) {
let msg = "Global-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}
}
} else {
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)
console.log(msg)
if (hasConsole) console.log(msg)
continue
}

if (data[domainURL][cookie.name] !== undefined && data[domainURL][cookie.name] === false) {
let msg = "Permitted cookie on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
continue
}

Expand All @@ -166,11 +169,11 @@ async function clearCookiesAction (action, data, cookies) {
if (data[domainURL] !== undefined && data[domainURL][cookieName] !== undefined && data[domainURL][cookieName] === true) {
let msg = "Deleted on '" + action + "', cookie: '" + cookieName + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
} else {
let msg = "Global-flag deleted on '" + action + "', cookie: '" + cookieName + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}
}

Expand All @@ -181,11 +184,11 @@ async function clearCookiesAction (action, data, cookies) {
if (data[domainURL] !== undefined && data[domainURL][cookie.name] !== undefined && data[domainURL][cookie.name] === true) {
let msg = "Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
} else {
let msg = "Global-flag deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}
}
}
Expand All @@ -195,14 +198,14 @@ async function clearCookiesAction (action, data, cookies) {
if (hasProfile && hasLogged && data['flagCookies_logged'][domainURL][cookie] !== undefined) {
let msg = "Allowed profile cookie on '" + action + "', cookie: '" + cookie + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
continue
}

if (data[domainURL][cookie] === false) {
let msg = "Permitted cookie on '" + action + "', cookie: '" + cookie + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
continue
}

Expand All @@ -214,7 +217,7 @@ async function clearCookiesAction (action, data, cookies) {
if (chrome.cookies.remove(details) !== null) {
let msg = "Deleted on '" + action + "', cookie: '" + cookieName + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}

continue
Expand All @@ -223,7 +226,7 @@ async function clearCookiesAction (action, data, cookies) {
if ((await browser.cookies.remove(details)) != null) {
let msg = "Deleted on '" + action + "', cookie: '" + cookie.name + "' for '" + domainURL + "'"
addToLogData(msg)
console.log(msg)
if (hasConsole) console.log(msg)
}
}
}
Expand All @@ -238,7 +241,7 @@ async function setDomainURLWrapper(activeTabs) {
let urlMatch = currentTab.url.replace(/\/www\./, '/').match(/(http|https):\/\/[a-zA-Z0-9öäüÖÄÜ.-]*\//)
if (urlMatch) {
domainURL = urlMatch[0]
console.log('Switched active domain to: ' + domainURL)
if (hasConsole) console.log('Switched active domain to: ' + domainURL)
}
}
}
Expand Down Expand Up @@ -270,13 +273,13 @@ async function setDomainURLOnActivation (activeInfo) {
function chromeUpdateLogData (data, writeData) {
function updatedData () {
if (chrome.runtime.lastError !== undefined) {
console.log('Chrome could not store data')
if (hasConsole) console.log('Chrome could not store data')

void chrome.runtime.lastError
return
}

console.log('Chrome updated the browser storage')
if (hasConsole) console.log('Chrome updated the browser storage')
}

if (writeData) {
Expand Down
50 changes: 36 additions & 14 deletions flagCookies.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Chrome
let useChrome = typeof (browser) === 'undefined'
let hasConsole = typeof (console) !== 'undefined'


// Chrome helpers
function checkChromeHadNoErrors () {
if (chrome.runtime.lastError) {
if (chrome.runtime.lastError.message !== undefined) {
console.log('Chrome had an error, with mesage: ' + chrome.runtime.lastError.message)
} else {
console.log('Chrome had an error.')
if (hasConsole) {
if (chrome.runtime.lastError.message !== undefined) {
console.log('Chrome had an error, with mesage: ' + chrome.runtime.lastError.message)
} else {
console.log('Chrome had an error.')
}
}

void chrome.runtime.lastError
Expand All @@ -21,47 +25,62 @@ function checkChromeHadNoErrors () {
function getChromeStorageForFunc (func) {
chrome.storage.local.get(null, function (data) {
if (checkChromeHadNoErrors()) {
console.log('Chrome retrieved storage data.')
if (hasConsole)console.log('Chrome retrieved storage data.')

func(data)
} else console.log('Chrome storage retrieval error.')
} else if (hasConsole) {
console.log('Chrome storage retrieval error.')
}
})
}

function getChromeStorageForFunc1 (func, par1) {
chrome.storage.local.get(null, function (data) {
if (checkChromeHadNoErrors()) {
console.log('Chrome retrieved storage data.')
if (hasConsole) console.log('Chrome retrieved storage data.')

func(data, par1)
} else console.log('Chrome storage retrieval error.')
} else if (hasConsole) {
console.log('Chrome storage retrieval error.')
}
})
}

function getChromeStorageForFunc2 (func, par1, par2) {
chrome.storage.local.get(null, function (data) {
if (checkChromeHadNoErrors()) {
console.log('Chrome retrieved storage data.')
if (hasConsole) console.log('Chrome retrieved storage data.')


func(data, par1, par2)
} else console.log('Chrome storage retrieval error.')
} else if (hasConsole) {
console.log('Chrome storage retrieval error.')
}
})
}

function getChromeStorageForFunc3 (func, par1, par2, par3) {
chrome.storage.local.get(null, function (data) {
if (checkChromeHadNoErrors()) {
console.log('Chrome retrieved storage data.')
if (hasConsole) console.log('Chrome retrieved storage data.')

func(data, par1, par2, par3)
} else console.log('Chrome storage retrieval error.')
} else if (hasConsole) {
console.log('Chrome storage retrieval error.')
}
})
}

function setChromeStorage (data) {
chrome.storage.local.set(data, function () {
if (checkChromeHadNoErrors()) console.log('Chrome updated the storage data.')
else console.log('Chrome updating storage error.')

if (checkChromeHadNoErrors()) {
if (hasConsole) {
console.log('Chrome updated the storage data.')
}
} else if (hasConsole) {
console.log('Chrome updating storage error.')
}
})
}

Expand Down Expand Up @@ -103,6 +122,9 @@ async function initDomainURLandProceed (tabs) {

if (useChrome) {
document.body.className = 'chrome'
if (navigator.appVersion.toLowerCase().indexOf("opr/") !== -1) {
document.body.className += ' opera'
}
chromeGetStorageAndCookiesForFunc(null, null, updateUIData)
return
}
Expand Down

0 comments on commit bd4fc93

Please sign in to comment.