Skip to content

Instantly share code, notes, and snippets.

@xgqfrms
Last active June 24, 2021 09:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xgqfrms/8d605a26561d59880ac21fb2499d0caf to your computer and use it in GitHub Desktop.
Save xgqfrms/8d605a26561d59880ac21fb2499d0caf to your computer and use it in GitHub Desktop.
前端监控-SDK
@xgqfrms
Copy link
Author

xgqfrms commented Apr 8, 2021

  1. sendBeacon 发送 FormData, 浏览器有长度限制 max limited String size
const autoReport = (timer = 10000) => {
    window.setInterval(() => {
        const stringData = registry.metrics();
        console.log('重复 bug ???', registry);
        // console.log('stringData ???', stringData);
        // axios.post(url, stringData).then(() => {
        //     // 0
        //     registry.reset();
        // });
        //
        const flag = navigator.sendBeacon(url, stringData);
        if(flag) {
            registry.reset();
        }
    }, timer);
};
  1. visibilityState & beforeunload & unload, 监控 tab 切换,页面关闭,刷新
document.visibilityState;
// "visible"

document.hidden;
// false

@xgqfrms
Copy link
Author

xgqfrms commented Apr 8, 2021

  1. pageshow & pagehide

  2. History API 重载

@xgqfrms
Copy link
Author

xgqfrms commented Jun 24, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment