chore: Modified sw analtyics tracker (#25966)
## Description Contains the changes to wait for 20s for the service worker to become ready before dispatching the registration failed event #### Type of change - Chore (housekeeping or task changes that don't impact user perception) > > ## Testing > #### How Has This Been Tested? - [x] Manual > > ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
This commit is contained in:
parent
235b106415
commit
51290d2f1d
|
|
@ -2,6 +2,7 @@ import { get } from "lodash";
|
|||
import {
|
||||
all,
|
||||
call,
|
||||
delay,
|
||||
put,
|
||||
race,
|
||||
select,
|
||||
|
|
@ -101,39 +102,30 @@ export function* waitForWidgetConfigBuild() {
|
|||
|
||||
export function* reportSWStatus() {
|
||||
const mode: APP_MODE = yield select(getAppMode);
|
||||
const startTime = Date.now();
|
||||
if ("serviceWorker" in navigator) {
|
||||
navigator.serviceWorker
|
||||
.getRegistrations()
|
||||
.then((registrations) => {
|
||||
if (registrations.length === 0) {
|
||||
return AnalyticsUtil.logEvent("SW_REGISTRATION_FAILED", {
|
||||
message: "Service worker not found",
|
||||
mode,
|
||||
});
|
||||
}
|
||||
const activeRegistrations = registrations.filter(
|
||||
(registration) => registration.active,
|
||||
);
|
||||
if (activeRegistrations.length === 0) {
|
||||
return AnalyticsUtil.logEvent("SW_REGISTRATION_FAILED", {
|
||||
message: "Service worker is not active",
|
||||
mode,
|
||||
});
|
||||
}
|
||||
AnalyticsUtil.logEvent("SW_REGISTRATION_SUCCESS", {
|
||||
message: "Service worker is active",
|
||||
mode,
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
AnalyticsUtil.logEvent("SW_REGISTRATION_FAILED", {
|
||||
message: "Failed to retrieve SW registrations",
|
||||
mode,
|
||||
});
|
||||
const result: { success: any; failed: any } = yield race({
|
||||
success: navigator.serviceWorker.ready.then((reg) => ({
|
||||
reg,
|
||||
timeTaken: Date.now() - startTime,
|
||||
})),
|
||||
failed: delay(20000),
|
||||
});
|
||||
if (result.success) {
|
||||
AnalyticsUtil.logEvent("SW_REGISTRATION_SUCCESS", {
|
||||
message: "Service worker is active",
|
||||
mode,
|
||||
timeTaken: result.success.timeTaken,
|
||||
});
|
||||
} else {
|
||||
AnalyticsUtil.logEvent("SW_REGISTRATION_FAILED", {
|
||||
message: "Service worker is not active in 20s",
|
||||
mode,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
AnalyticsUtil.logEvent("SW_REGISTRATION_FAILED", {
|
||||
message: "SW is not supported",
|
||||
message: "Service worker is not supported",
|
||||
mode,
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user