Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for surrogate included in head tag #170

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions privacy-protections/surrogates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
color: black;
}
</style>
<script id="head-tag" src="//google-analytics.com/analytics.js"></script>
</head>
<p><a href="../../">[Home]</a> ↣ <a href="../">[Privacy Protections Tests]</a> ↣ <strong>[Surrogates Test Page]</strong></p>

Expand Down
69 changes: 48 additions & 21 deletions privacy-protections/surrogates/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ function checkSurrogate () {
}

const surrogates = {
head: {
notes: 'Loading surrogate in <head>',
load: () => Promise.resolve(checkSurrogate()), // included in the html
cleanUp: () => {
document.getElementById('head-tag').remove();
delete window.ga;
}
},
'main-frame': {
url: 'https://google-analytics.com/analytics.js',
notes: 'Loading surrogate in the main frame.',
Expand Down Expand Up @@ -108,36 +116,55 @@ const surrogates = {

return promise;
}
},
'delayed-set': {
notes: 'Set script src after insert',
url: 'https://google-analytics.com/analytics.js',
delay: true,
test: checkSurrogate,
cleanUp: () => { delete window.ga; }
}
};

(async function loadSurrogates () {
for (const [name, testData] of Object.entries(surrogates)) {
if (testData.url) {
await new Promise((resolve, reject) => {
const s = document.createElement('script');
async function injectSurrogate (testData) {
return new Promise((resolve, reject) => {
const s = document.createElement('script');

if (testData.crossOrigin) {
s.crossOrigin = testData.crossOrigin;
}
if (testData.integrity) {
s.integrity = testData.integrity;
}
if (testData.crossOrigin) {
s.crossOrigin = testData.crossOrigin;
}
if (testData.integrity) {
s.integrity = testData.integrity;
}

s.onload = () => {
updateTable({ name, testData });
resolve();
};

s.onload = () => {
updateTable({ name, testData });
resolve();
};
s.onerror = (error) => {
updateTable({ name, testData, error });
resolve();
};

s.onerror = (error) => {
updateTable({ name, testData, error });
resolve();
};
if (!testData.delay) {
s.src = testData.url;
}

document.body.appendChild(s);

if (testData.delay) {
setTimeout(() => {
s.src = testData.url;
}, 500);
}
});
}

document.body.appendChild(s);
});
(async function loadSurrogates () {
for (const [name, testData] of Object.entries(surrogates)) {
if (testData.url) {
await injectSurrogate(testData);
} else {
testData.load().then(result => {
testData.test = () => result;
Expand Down
Loading