Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(recording-mode): handle fulfilled requests after recording error #642

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions pwa/src/service-worker/recording-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,21 @@ export function handleRecordedRequest({ request, event }) {
return handleRecordedResponse(request, response, event.clientId)
})
.catch(error => {
console.error(error)
stopRecording(error, event.clientId)
})
}

/** Response handler during recording mode */
function handleRecordedResponse(request, response, clientId) {
const recordingState = self.clientRecordingStates[clientId]

if (!recordingState) {
// It's likely that the recording was stopped due to an error.
// There will be plenty of error messages logged; no need for another
// one here
return response
}

// add response to temp cache - when recording is successful, move to permanent cache
const tempCacheKey = getCacheKey('temp', clientId)
addToCache(tempCacheKey, request, response)
Expand Down Expand Up @@ -103,13 +110,16 @@ function startRecordingTimeout(clientId) {
function stopRecording(error, clientId) {
const recordingState = self.clientRecordingStates[clientId]

console.debug('[SW] Stopping recording', { clientId, recordingState })
clearTimeout(recordingState?.recordingTimeout)
if (recordingState) {
console.debug('[SW] Stopping recording', { clientId, recordingState })
clearTimeout(recordingState.recordingTimeout)
}

// In case of error, notify client and remove recording
// In case of error, notify client and remove recording.
// Post message even if !recordingState to ensure client stops.
if (error) {
self.clients.get(clientId).then(client => {
// todo: use plain object instead of Error for firefox compatibility
// use plain object instead of Error for firefox compatibility
client.postMessage({
type: swMsgs.recordingError,
payload: {
Expand Down