修复:Chrome 点击离开时出现原生"离开网站"弹窗闪烁
主动调用 remove 移除 beforeunload 监听后再导航, Chrome 不再触发原生确认框,Edge 行为不变
This commit is contained in:
@@ -951,6 +951,10 @@
|
|||||||
|
|
||||||
// ── 退出房间 ─────────────────────────────────────
|
// ── 退出房间 ─────────────────────────────────────
|
||||||
async function leaveRoom() {
|
async function leaveRoom() {
|
||||||
|
// 主动移除 beforeunload 监听,防止 Chrome 触发"离开网站?"原生弹窗
|
||||||
|
window.removeEventListener('beforeunload', sendLeaveBeacon);
|
||||||
|
clearTimeout(visibilityTimer);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fetch(window.chatContext.leaveUrl, {
|
await fetch(window.chatContext.leaveUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
@@ -970,6 +974,7 @@
|
|||||||
}, 500);
|
}, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ── 关闭/离开页面时自动调用 leave,结算勤务时长 ──────────────────────
|
// ── 关闭/离开页面时自动调用 leave,结算勤务时长 ──────────────────────
|
||||||
// 使用 sendBeacon 确保浏览器关闭时请求也能发出(比 fetch 更可靠)
|
// 使用 sendBeacon 确保浏览器关闭时请求也能发出(比 fetch 更可靠)
|
||||||
function sendLeaveBeacon() {
|
function sendLeaveBeacon() {
|
||||||
|
|||||||
Reference in New Issue
Block a user