From 29070be8e3b75398d42bc9d577d312e8ec52613f Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Fri, 1 Oct 2021 01:20:46 +0200 Subject: [PATCH 1/5] result->value for consistency --- privacy-protections/referrer-trimming/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/privacy-protections/referrer-trimming/main.js b/privacy-protections/referrer-trimming/main.js index ea4eed6..8c03715 100644 --- a/privacy-protections/referrer-trimming/main.js +++ b/privacy-protections/referrer-trimming/main.js @@ -26,11 +26,11 @@ function generateNavigationTest (url) { const result = [ { test: 'js', - result: currentURL.searchParams.get('js') + value: currentURL.searchParams.get('js') }, { test: 'header', - result: currentURL.searchParams.get('header') + value: currentURL.searchParams.get('header') } ]; localStorage.setItem(key, JSON.stringify(result)); From 8558e30ef911b1a1dcbddbb451451e5c414a5e6e Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Fri, 1 Oct 2021 01:39:59 +0200 Subject: [PATCH 2/5] Flatten test results, separate value from error message. --- .../storage-blocking/iframe.js | 6 ++-- privacy-protections/storage-blocking/main.js | 31 ++++++++++++------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/privacy-protections/storage-blocking/iframe.js b/privacy-protections/storage-blocking/iframe.js index a27044e..297319d 100644 --- a/privacy-protections/storage-blocking/iframe.js +++ b/privacy-protections/storage-blocking/iframe.js @@ -43,7 +43,8 @@ function retrieveData () { })) .catch(e => ({ test: test.id, - result: e.message + result: null, + error: e.message })); } else { return Promise.resolve({ @@ -54,7 +55,8 @@ function retrieveData () { } catch (e) { return Promise.resolve({ test: test.id, - result: e.message ? e.message : e + result: null, + error: e.message ? e.message : e }); } })); diff --git a/privacy-protections/storage-blocking/main.js b/privacy-protections/storage-blocking/main.js index 64a59c4..45c572f 100644 --- a/privacy-protections/storage-blocking/main.js +++ b/privacy-protections/storage-blocking/main.js @@ -271,15 +271,16 @@ function retrieveData () { testsSummaryDiv.innerText = `Retrieved data from ${all} storage mechanisms${failed > 0 ? ` (${failed} failed)` : ''}. Click for details.`; } + function addTestResult (testId, value) { + results.results.push({ + id: testId, + value: value + }); + } + tests.concat(commonTests).forEach(test => { all++; - const resultObj = { - id: test.id, - value: null - }; - results.results.push(resultObj); - const li = document.createElement('li'); li.id = `test-${test.id.replace(' ', '-')}`; li.innerHTML = `${test.id} - `; @@ -294,25 +295,31 @@ function retrieveData () { result .then(data => { if (Array.isArray(data)) { - valueSpan.innerHTML = ``; - } else if (data) { - valueSpan.innerHTML = JSON.stringify(data, null, 2); - } + valueSpan.innerHTML = ``; + + data.forEach(item => addTestResult(`${test.id} - ${item.test}`, item.result)); + } else { + if (data) { + valueSpan.innerHTML = JSON.stringify(data, null, 2); + } - resultObj.value = data; + addTestResult(test.id, data); + } }) .catch(e => { failed++; valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`; + addTestResult(test.id, null); updateSummary(); }); } else { valueSpan.innerText = JSON.stringify(result, null, 2) || undefined; - resultObj.value = result || null; + addTestResult(test.id, result || null); } } catch (e) { failed++; valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`; + addTestResult(test.id, null); } }); From 79d912e64896889f1d5ca519a118a4ed8bf8ef14 Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Fri, 1 Oct 2021 01:48:08 +0200 Subject: [PATCH 3/5] result -> value for consistency --- privacy-protections/storage-blocking/iframe.js | 16 ++++++++-------- privacy-protections/storage-blocking/main.js | 6 +++--- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/privacy-protections/storage-blocking/iframe.js b/privacy-protections/storage-blocking/iframe.js index 297319d..4c5ad4d 100644 --- a/privacy-protections/storage-blocking/iframe.js +++ b/privacy-protections/storage-blocking/iframe.js @@ -9,22 +9,22 @@ function storeData (randomNumber) { return result .then(() => ({ test: test.id, - result: 'OK' + value: 'OK' })) .catch(e => ({ test: test.id, - result: e.message + value: e.message })); } else { return Promise.resolve({ test: test.id, - result: 'OK' + value: 'OK' }); } } catch (e) { return Promise.resolve({ test: test.id, - result: e.message ? e.message : e + value: e.message ? e.message : e }); } })); @@ -39,23 +39,23 @@ function retrieveData () { return result .then(value => ({ test: test.id, - result: value + value: value })) .catch(e => ({ test: test.id, - result: null, + value: null, error: e.message })); } else { return Promise.resolve({ test: test.id, - result: result + value: result }); } } catch (e) { return Promise.resolve({ test: test.id, - result: null, + value: null, error: e.message ? e.message : e }); } diff --git a/privacy-protections/storage-blocking/main.js b/privacy-protections/storage-blocking/main.js index 45c572f..1661bc6 100644 --- a/privacy-protections/storage-blocking/main.js +++ b/privacy-protections/storage-blocking/main.js @@ -231,7 +231,7 @@ function storeData () { result .then(result => { if (Array.isArray(result)) { - valueSpan.innerHTML = `
    ${result.map(r => `
  • ${r.test} - ${r.result}
  • `).join('')}
`; + valueSpan.innerHTML = `
    ${result.map(r => `
  • ${r.test} - ${r.value}
  • `).join('')}
`; } else if (result && result !== 'OK') { valueSpan.innerHTML = JSON.stringify(result, null, 2); } else { @@ -295,9 +295,9 @@ function retrieveData () { result .then(data => { if (Array.isArray(data)) { - valueSpan.innerHTML = `
    ${data.map(r => `
  • ${r.test} - ${r.result} ${r.error ? '(❌ ' + r.error + ')' : ''}
  • `).join('')}
`; + valueSpan.innerHTML = `
    ${data.map(r => `
  • ${r.test} - ${r.value} ${r.error ? '(❌ ' + r.error + ')' : ''}
  • `).join('')}
`; - data.forEach(item => addTestResult(`${test.id} - ${item.test}`, item.result)); + data.forEach(item => addTestResult(`${test.id} - ${item.test}`, item.value)); } else { if (data) { valueSpan.innerHTML = JSON.stringify(data, null, 2); From 919411fce23f4e1d8a48306ff08e1cc6a34e555d Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Fri, 1 Oct 2021 01:51:22 +0200 Subject: [PATCH 4/5] Referrer trimming - flatten results object. --- privacy-protections/referrer-trimming/main.js | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/privacy-protections/referrer-trimming/main.js b/privacy-protections/referrer-trimming/main.js index 8c03715..0ecde34 100644 --- a/privacy-protections/referrer-trimming/main.js +++ b/privacy-protections/referrer-trimming/main.js @@ -148,13 +148,14 @@ function runTests () { testsSummaryDiv.innerText = `Performed ${all} tests${failed > 0 ? ` (${failed} failed)` : ''}. Click for details.`; } - for (const test of tests) { - const resultObj = { - id: test.id, - value: null - }; - results.results.push(resultObj); + function addTestResult (testId, value) { + results.results.push({ + id: testId, + value: value + }); + } + for (const test of tests) { const li = document.createElement('li'); li.id = `test-${test.id.replace(' ', '-')}`; li.innerHTML = `${test.id} - `; @@ -172,30 +173,40 @@ function runTests () { result .then(data => { if (Array.isArray(data)) { - valueSpan.innerHTML = `
    ${data.map(r => `
  • ${r.test} - ${r.result}
  • `).join('')}
`; - } else if (data) { - valueSpan.innerHTML = JSON.stringify(data, null, 2); - } + valueSpan.innerHTML = `
    ${data.map(r => `
  • ${r.test} - ${r.value}
  • `).join('')}
`; + + data.forEach(item => addTestResult(`${test.id} - ${item.test}`, item.result)); + } else { + if (data) { + valueSpan.innerHTML = JSON.stringify(data, null, 2); + } - resultObj.value = data; + addTestResult(test.id, data); + } }) .catch(e => { failed++; valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`; + addTestResult(test.id, null); updateSummary(); }); } else { if (Array.isArray(result)) { - valueSpan.innerHTML = `
    ${result.map(r => `
  • ${r.test} - ${r.result}
  • `).join('')}
`; - } else if (result) { - valueSpan.innerHTML = JSON.stringify(result, null, 2); - } + valueSpan.innerHTML = `
    ${result.map(r => `
  • ${r.test} - ${r.value}
  • `).join('')}
`; - resultObj.value = result || null; + result.forEach(item => addTestResult(`${test.id} - ${item.test}`, item.value)); + } else { + if (result) { + valueSpan.innerHTML = JSON.stringify(result, null, 2); + } + + addTestResult(test.id, result || null); + } } } catch (e) { failed++; valueSpan.innerHTML = `❌ error thrown ("${e.message ? e.message : e}")`; + addTestResult(test.id, null); } all++; From b07247be544deabf4855544975f1ccf580b26c39 Mon Sep 17 00:00:00 2001 From: Konrad Dzwinel Date: Fri, 1 Oct 2021 02:06:00 +0200 Subject: [PATCH 5/5] Expose click-to-play results in a global variable. Move JS from HTML to a JS file. --- privacy-protections/click-to-load/index.html | 83 +-------------- privacy-protections/click-to-load/main.js | 100 +++++++++++++++++++ 2 files changed, 101 insertions(+), 82 deletions(-) create mode 100644 privacy-protections/click-to-load/main.js diff --git a/privacy-protections/click-to-load/index.html b/privacy-protections/click-to-load/index.html index f3a694e..0c6d253 100644 --- a/privacy-protections/click-to-load/index.html +++ b/privacy-protections/click-to-load/index.html @@ -56,88 +56,7 @@

Objects in iFrames

Groups don't currently allow iFrame displays, but the documentation still shows this as a valid method of showing groups, so it's included here in case it changes again in the future


- + diff --git a/privacy-protections/click-to-load/main.js b/privacy-protections/click-to-load/main.js new file mode 100644 index 0000000..6ec0789 --- /dev/null +++ b/privacy-protections/click-to-load/main.js @@ -0,0 +1,100 @@ +let facebookCalls = 0; +let fbIFrames = 0; + +// object that contains results of all tests +const results = { + page: 'facebook-click-to-load', + date: (new Date()).toUTCString(), + results: [] +}; + +function updateResults () { + results.results = [ + { + id: 'facebookCalls', + value: facebookCalls + }, + { + id: 'fbIFrames', + value: fbIFrames + } + ]; + + document.getElementById('facebook_iFrames').innerHTML = fbIFrames; + document.getElementById('facebook_call_count').innerHTML = facebookCalls; +} + +// Find all the iFrames currently on page. +const frameNodes = document.querySelectorAll('iFrame'); +fbIFrames = frameNodes.length; +updateResults(); + +// This initializes the facebook SDK. +window.fbAsyncInit = function () { + // eslint-disable-next-line no-undef + FB.init({ + appId: '', + autoLogAppEvents: true, + xfbml: true, + version: 'v9.0' + }); + + function fbLogin () { + const displayArea = document.getElementById('loginResponse'); + displayArea.innerHTML = 'Calling FB SDK... '; + // eslint-disable-next-line no-undef + FB.login(function (response) { + if (response.authResponse) { + displayArea.innerHTML = 'Starting FB login... '; + // eslint-disable-next-line no-undef + FB.api('/me', function (response) { + displayArea.innerHTML = `Logged in as ${response.name}`; + }); + } else { + displayArea.innerHTML = 'User cancelled login or did not fully authorize.'; + } + }); + } + + const loginButton = document.getElementById('custom-fb-login-button'); + loginButton.addEventListener('click', fbLogin); +}; + +function facebookObserver (list, observer) { + const resourceLoads = list.getEntriesByType('resource'); + for (const resource of resourceLoads) { + if (resource.name.match(/facebook.com|facebook.net/)) { + /* Observer still counts calls that fail, but the duration is less. In testing, + * failed iFrames always returned in around 100 or less, with success generally being + * above 200. Occasionally, a loaded resource comes in around 150. If Facebook requests + * are allowed, there will also be other resources that load - scripts and content + * which will always be counted. + */ + if (resource.initiatorType !== 'iframe' || resource.duration > 150) { + facebookCalls += 1; + } + } + } + + updateResults(); +} + +const observer = new PerformanceObserver(facebookObserver); +observer.observe({ entryTypes: ['resource'] }); + +function downloadTheResults () { + const data = JSON.stringify(results); + const a = document.createElement('a'); + const url = window.URL.createObjectURL(new Blob([data], { type: 'application/json' })); + a.href = url; + a.download = 'facebook-click-to-load-results.json'; + + document.body.appendChild(a); + a.click(); + + window.URL.revokeObjectURL(url); + a.remove(); +} + +const downloadButton = document.querySelector('#download'); +downloadButton.addEventListener('click', () => downloadTheResults());