diff --git a/src/core/drive/navigator.ts b/src/core/drive/navigator.ts index 768cf7123..6b87a3126 100644 --- a/src/core/drive/navigator.ts +++ b/src/core/drive/navigator.ts @@ -44,11 +44,7 @@ export class Navigator { this.stop() this.formSubmission = new FormSubmission(this, form, submitter, true) - if (this.formSubmission.isIdempotent) { - this.proposeVisit(this.formSubmission.fetchRequest.url, { action: this.getActionForFormSubmission(this.formSubmission) }) - } else { - this.formSubmission.start() - } + this.formSubmission.start() } stop() { @@ -92,8 +88,9 @@ export class Navigator { this.view.clearSnapshotCache() } - const { statusCode } = fetchResponse - const visitOptions = { response: { statusCode, responseHTML } } + const { statusCode, redirected } = fetchResponse + const action = this.getActionForFormSubmission(formSubmission) + const visitOptions = { action, response: { statusCode, responseHTML, redirected } } this.proposeVisit(fetchResponse.location, visitOptions) } } diff --git a/src/core/drive/visit.ts b/src/core/drive/visit.ts index 7b050c1cb..624992dec 100644 --- a/src/core/drive/visit.ts +++ b/src/core/drive/visit.ts @@ -51,6 +51,7 @@ const defaultOptions: VisitOptions = { export type VisitResponse = { statusCode: number, + redirected: boolean, responseHTML?: string } @@ -259,7 +260,7 @@ export class Visit implements FetchRequestDelegate { } followRedirect() { - if (this.redirectedToLocation && !this.followedRedirect) { + if (this.redirectedToLocation && !this.followedRedirect && this.response?.redirected) { this.adapter.visitProposedToLocation(this.redirectedToLocation, { action: 'replace', response: this.response @@ -289,25 +290,27 @@ export class Visit implements FetchRequestDelegate { async requestSucceededWithResponse(request: FetchRequest, response: FetchResponse) { const responseHTML = await response.responseHTML + const { redirected, statusCode } = response if (responseHTML == undefined) { - this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch }) + this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch, redirected }) } else { this.redirectedToLocation = response.redirected ? response.location : undefined - this.recordResponse({ statusCode: response.statusCode, responseHTML }) + this.recordResponse({ statusCode: statusCode, responseHTML, redirected }) } } async requestFailedWithResponse(request: FetchRequest, response: FetchResponse) { const responseHTML = await response.responseHTML + const { redirected, statusCode } = response if (responseHTML == undefined) { - this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch }) + this.recordResponse({ statusCode: SystemStatusCode.contentTypeMismatch, redirected }) } else { - this.recordResponse({ statusCode: response.statusCode, responseHTML }) + this.recordResponse({ statusCode: statusCode, responseHTML, redirected }) } } requestErrored(request: FetchRequest, error: Error) { - this.recordResponse({ statusCode: SystemStatusCode.networkFailure }) + this.recordResponse({ statusCode: SystemStatusCode.networkFailure, redirected: false }) } requestFinished() { diff --git a/src/core/frames/frame_controller.ts b/src/core/frames/frame_controller.ts index 7727f6491..06efcc4b6 100644 --- a/src/core/frames/frame_controller.ts +++ b/src/core/frames/frame_controller.ts @@ -152,13 +152,9 @@ export class FrameController implements AppearanceObserverDelegate, FetchRequest this.reloadable = false this.formSubmission = new FormSubmission(this, element, submitter) - if (this.formSubmission.fetchRequest.isIdempotent) { - this.navigateFrame(element, this.formSubmission.fetchRequest.url.href, submitter) - } else { - const { fetchRequest } = this.formSubmission - this.prepareHeadersForRequest(fetchRequest.headers, fetchRequest) - this.formSubmission.start() - } + const { fetchRequest } = this.formSubmission + this.prepareHeadersForRequest(fetchRequest.headers, fetchRequest) + this.formSubmission.start() } // Fetch request delegate diff --git a/src/observers/form_submit_observer.ts b/src/observers/form_submit_observer.ts index 7ac928385..0d3443c5c 100644 --- a/src/observers/form_submit_observer.ts +++ b/src/observers/form_submit_observer.ts @@ -36,7 +36,7 @@ export class FormSubmitObserver { const submitter = event.submitter || undefined if (form) { - const method = submitter?.getAttribute("formmethod") || form.method + const method = submitter?.getAttribute("formmethod") || form.getAttribute("method") if (method != "dialog" && this.delegate.willSubmitForm(form, submitter)) { event.preventDefault() diff --git a/src/tests/fixtures/form.html b/src/tests/fixtures/form.html index 0740572e8..079ca9a01 100644 --- a/src/tests/fixtures/form.html +++ b/src/tests/fixtures/form.html @@ -18,7 +18,12 @@