0

我正在向我们的 UI 添加日志记录以跟踪页面加载持续时间的各个方面,包括 BE API 调用从服务器返回所花费的时间。我知道在过去,切换选项卡会导致setTimeout/IntervalrequestAnimationFrame等问题,但不确定这是否适用于其他较新的异步功能,如生成器函数、获取或性能 API。

任何人都可以确认以下是否可以,或者如果用户在 API 调用正在进行时切换回另一个选项卡几分钟后,API 调用的记录持续时间是否不正确?

(我们正在使用 React、Redux、Redux Sagas、Babel、Webpack 和 whatwg-fetch)

const { name, get } = api.foo;
const { mark, getEntriesByName } = window.performance;

mark(name);

response = yield call(get, payload); // user switches to another tab while processing

// user switches back after 2 minutes

const duration = getEntriesByName(name).pop().duration;
yield put(actions.logQueryDuration(name, duration))

in the above example, if the API call actually only takes 10 seconds to return, will the logged duration show 10 seconds or 2 minutes?

Thanks!

4

0 回答 0