chore: added correct referrer policy

This commit is contained in:
mildtomato committed 2021-01-29 14:40:57 +08:00
1 parent d6b7b6ff91
commit 3c3a16a64a
2 files changed
+44 -14

No files matched your search

+43 -13
View File
@@ -1,18 +1,48 @@
function telemetry() {
return fetch('https://app.supabase.io/api/telemetry/page', {
mode: 'cors', // 'cors' by default,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({
referrer: document.referrer,
title: document.title,
}),
}).catch((error) => {
console.error('Error at telemetry - post:', error)
setTimeout(function () {
return fetch('https://app.supabase.io/api/telemetry/page', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
referrerPolicy: 'no-referrer-when-downgrade',
body: JSON.stringify({
referrer: document.referrer,
title: document.title,
}),
}).catch((error) => {
console.error('Error at telemetry - post:', error)
})
}, 1000)
}
function pageState() {
;(function () {
var pushState = history.pushState
var replaceState = history.replaceState
history.pushState = function () {
pushState.apply(history, arguments)
window.dispatchEvent(new Event('pushstate'))
window.dispatchEvent(new Event('locationchange'))
}
history.replaceState = function () {
replaceState.apply(history, arguments)
window.dispatchEvent(new Event('replacestate'))
window.dispatchEvent(new Event('locationchange'))
}
window.addEventListener('popstate', function () {
window.dispatchEvent(new Event('locationchange'))
})
})()
window.addEventListener('locationchange', function () {
telemetry()
})
}
pageState()
telemetry()
+1 -1
View File
@@ -5,12 +5,12 @@ interface DataProps {
export const post = (url: string, data: DataProps, options = {}) => {
return fetch(url, {
mode: 'cors', // 'cors' by default,
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
referrerPolicy: 'no-referrer-when-downgrade',
body: JSON.stringify(data),
...options,
}).catch((error) => {