diff --git a/src/core/frames/frame_controller.ts b/src/core/frames/frame_controller.ts index 06efcc4b6..da8c7a847 100644 --- a/src/core/frames/frame_controller.ts +++ b/src/core/frames/frame_controller.ts @@ -172,8 +172,16 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest } async requestSucceededWithResponse(request: FetchRequest, response: FetchResponse) { - await this.loadResponse(response) - this.resolveVisitPromise() + const { location, redirected, statusCode } = response + + if (redirected && response.header("Turbo-Frame") == "_top") { + const responseHTML = await response.responseHTML + + session.visit(location, { response: { statusCode, redirected, responseHTML } }) + } else { + await this.loadResponse(response) + this.resolveVisitPromise() + } } requestFailedWithResponse(request: FetchRequest, response: FetchResponse) { @@ -198,8 +206,13 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest } formSubmissionSucceededWithResponse(formSubmission: FormSubmission, response: FetchResponse) { - const frame = this.findFrameElement(formSubmission.formElement, formSubmission.submitter) - frame.delegate.loadResponse(response) + if (response.redirected && response.header("Turbo-Frame") == "_top") { + session.view.clearSnapshotCache() + session.visit(response.location) + } else { + const frame = this.findFrameElement(formSubmission.formElement, formSubmission.submitter) + frame.delegate.loadResponse(response) + } } formSubmissionFailedWithResponse(formSubmission: FormSubmission, fetchResponse: FetchResponse) { diff --git a/src/tests/fixtures/form.html b/src/tests/fixtures/form.html index 079ca9a01..095e146ff 100644 --- a/src/tests/fixtures/form.html +++ b/src/tests/fixtures/form.html @@ -181,6 +181,11 @@