This is the cherry pick merge for the M73 branch which was approved here:

[Autofill Assistant] Fix delayed prompt state issue.

Before this patch, the controller would stay in the running state
between the end of a script and the time runnable scripts were found.

In practice, for users, this meant that the website could be available,
but keyboard could be unavailable until a runnable script is found.
During that time the progress bar should have been pulsing but wasn't.

After this patch, the controller enters the prompt state immediately
after running a script, starting the pulsing and making the keyboard
available right away.

The cost of this is that in some corner case, the state can switch to
the prompt state then quickly enter an error case.

Bug: 122825639
Change-Id: Id4927a750370ec59e5c1216ebac01d54e377b2f3
Commit-Queue: Stephane Zermatten <>
Reviewed-by: Mathias Carlen <>
Cr-Original-Commit-Position: refs/heads/master@{#626996}(cherry picked from commit ba1715e2e1d192e2564252c91186fd1e4e184df2)
Reviewed-by: Stephane Zermatten <>
Cr-Commit-Position: refs/branch-heads/3683@{#112}
Cr-Branched-From: e51029943e0a38dd794b73caaf6373d5496ae783-refs/heads/master@{#625896}
diff --git a/components/autofill_assistant/browser/ b/components/autofill_assistant/browser/
index 7509aa7..cae0a4c 100644
--- a/components/autofill_assistant/browser/
+++ b/components/autofill_assistant/browser/
@@ -318,6 +318,7 @@
       DLOG(ERROR) << "Unexpected value for at_end: " << result.at_end;
+  EnterState(AutofillAssistantState::PROMPT);
diff --git a/components/autofill_assistant/browser/ b/components/autofill_assistant/browser/
index aea610c1..689e163 100644
--- a/components/autofill_assistant/browser/
+++ b/components/autofill_assistant/browser/
@@ -513,6 +513,7 @@
   EXPECT_EQ(AutofillAssistantState::STOPPED, GetUiDelegate()->GetState());
   EXPECT_THAT(states_, ElementsAre(AutofillAssistantState::RUNNING,
+                                   AutofillAssistantState::PROMPT,
 }  // namespace autofill_assistant