change(tracker): added worker restart
This commit is contained in:
parent
48a42fefd2
commit
1c94807541
5 changed files with 25 additions and 17 deletions
|
|
@ -4,6 +4,7 @@
|
|||
- Added `{ withCurrentTime: true }` to `tracker.getSessionURL` method which will return sessionURL with current session's timestamp
|
||||
- Added Network module that captures fetch/xhr by default (with no plugin required)
|
||||
- Use `timeOrigin()` instead of `performance.timing.navigationStart` in ResourceTiming messages
|
||||
- Added app restart when service worker died after inactivity (mobile safari)
|
||||
|
||||
## 4.1.8
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "@openreplay/tracker",
|
||||
"description": "The OpenReplay tracker main package",
|
||||
"version": "4.1.9-beta.2",
|
||||
"version": "4.1.9-beta.4",
|
||||
"keywords": [
|
||||
"logging",
|
||||
"replay"
|
||||
|
|
|
|||
|
|
@ -26,4 +26,4 @@ type Failure = {
|
|||
reason: string
|
||||
}
|
||||
|
||||
export type FromWorkerData = 'restart' | Failure
|
||||
export type FromWorkerData = 'restart' | Failure | 'not_init'
|
||||
|
|
|
|||
|
|
@ -165,6 +165,8 @@ export default class App {
|
|||
if (data === 'restart') {
|
||||
this.stop(false)
|
||||
this.start({}, true)
|
||||
} else if (data === 'not_init') {
|
||||
console.warn('WebWorker: writer not initialised. Restarting tracker')
|
||||
} else if (data.type === 'failure') {
|
||||
this.stop(false)
|
||||
this._debug('worker_failed', data.reason)
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ const AUTO_SEND_INTERVAL = 10 * 1000
|
|||
let sender: QueueSender | null = null
|
||||
let writer: BatchWriter | null = null
|
||||
let workerStatus: WorkerStatus = WorkerStatus.NotActive
|
||||
|
||||
let afterSleepRestarts = 0
|
||||
function finalize(): void {
|
||||
if (!writer) {
|
||||
return
|
||||
|
|
@ -82,22 +82,27 @@ self.onmessage = ({ data }: any): any => {
|
|||
}
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
// Message[]
|
||||
if (!writer) {
|
||||
throw new Error('WebWorker: writer not initialised. Service Should be Started.')
|
||||
}
|
||||
const w = writer
|
||||
data.forEach((message) => {
|
||||
if (message[0] === MType.SetPageVisibility) {
|
||||
if (message[1]) {
|
||||
// .hidden
|
||||
restartTimeoutID = setTimeout(() => initiateRestart(), 30 * 60 * 1000)
|
||||
} else {
|
||||
clearTimeout(restartTimeoutID)
|
||||
if (writer !== null) {
|
||||
const w = writer
|
||||
data.forEach((message) => {
|
||||
if (message[0] === MType.SetPageVisibility) {
|
||||
if (message[1]) {
|
||||
// .hidden
|
||||
restartTimeoutID = setTimeout(() => initiateRestart(), 30 * 60 * 1000)
|
||||
} else {
|
||||
clearTimeout(restartTimeoutID)
|
||||
}
|
||||
}
|
||||
w.writeMessage(message)
|
||||
})
|
||||
}
|
||||
if (!writer) {
|
||||
postMessage('not_init')
|
||||
if (afterSleepRestarts === 0) {
|
||||
afterSleepRestarts += 1
|
||||
initiateRestart()
|
||||
}
|
||||
w.writeMessage(message)
|
||||
})
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue