Skip to content

Commit

Permalink
feat: test beforeunload compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Leoglme committed Feb 18, 2024
1 parent 205fe91 commit 6aa7951
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions public/mon-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,39 @@


document.addEventListener("unload", () => {
console.log("unload")
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
.then(json => console.log(json))
fetch('https://analytics.dibodev.com/projects', {
method: 'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({ domain: `unload${Math.random()}` })
}).then(res => res.json())
.then(res => console.log(res));
});


document.addEventListener("visibilitychange",() => {
fetch('https://analytics.dibodev.com/projects', {
method: 'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({ domain: `visibilitychange${Math.random()}` })
}).then(res => res.json())
.then(res => console.log(res));
})

// ios safari does not support pagehide
window.addEventListener('pagehide', () => {
fetch('https://analytics.dibodev.com/projects', {
method: 'POST',
headers: {
'Accept': 'application/json, text/plain, */*',
'Content-Type': 'application/json'
},
body: JSON.stringify({ domain: `pagehide${Math.random()}` })
}).then(res => res.json())
.then(res => console.log(res));
})

0 comments on commit 6aa7951

Please sign in to comment.