mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
20 lines
744 B
JavaScript
20 lines
744 B
JavaScript
// Browser-only diagnostic observer; messages and termination still use native workers.
|
|
export function observeWorkers() {
|
|
const NativeWorker = window.Worker
|
|
window.workerEvidence = []
|
|
window.Worker = class extends NativeWorker {
|
|
constructor(url, options) {
|
|
super(url, options)
|
|
const record = { url: String(url), messages: [], errors: [], terminated: 0 }
|
|
window.workerEvidence.push(record)
|
|
this.addEventListener('message', event => record.messages.push(event.data?.event))
|
|
this.addEventListener('error', event => record.errors.push(event.message))
|
|
const terminate = this.terminate.bind(this)
|
|
this.terminate = () => {
|
|
record.terminated++
|
|
return terminate()
|
|
}
|
|
}
|
|
}
|
|
}
|