amplify-ui: Amplify Liveness intermitently does not ask for Camera Permission on FireFox mobile (iOS & Android)

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Liveness

How is your app built?

Vite

What browsers are you seeing the problem on?

Firefox

Which region are you seeing the problem in?

us-east-1

Please describe your bug.

Sometimes the package does not ask for camera permission on Firefox mobile, and keep on an infinite loop displaying the waitingCameraPermissionText.

Please note that it is intermittent, sometimes works, sometimes does not but it fails in most cases. It works fine on Firefox for desktop and other browsers, the issue is only on Firefox mobile.

What’s the expected behaviour?

We should see a pop up requesting the camera access permission or display the component on the screen.

Help us reproduce the bug!

  • Create a vite react app
  • Install amplify liveness as described in the documentation
  • Use the example provided in the documentation to create a sessions ID

Code Snippet

// Put your code below this line.
import React, { useEffect, useState } from "react";
import { FaceLivenessDetector } from "@aws-amplify/ui-react-liveness";
import { Loader, ThemeProvider, Button, Flex } from "@aws-amplify/ui-react";
import CancelIcon from "../components/icons/CancelIcon";
import CheckIcon from "../components/icons/CheckIcon";
import { API_URL } from "../data/constants";
import { FaceLivenessDictionary } from "../data/translations";
import { useTranslation } from "react-i18next";
import { extractLanguageCode } from "../utils/common";

const FaceLiveness = ({ handleNextStep, dispatch, acessToken }) => {
  const { t, i18n } = useTranslation();
  const [language, setLanguage] = useState("");
  const [loading, setLoading] = useState(true);
  const [createLivenessApiData, setCreateLivenessApiData] = useState(null);
  const [result, setResult] = useState({
    completed: false,
    ok: false,
  });

  const handleError = (error) => {
    dispatch({
      type: "awsLivenessError",
      value: error,
    });
  };

  const fetchCreateLiveness = async () => {
    try {
      const response = await fetch(`${API_URL}/create_face_liveness_response`, {
        headers: new Headers({
          Authorization: `Bearer ${acessToken}`,
        }),
      });
      const json = await response.json();
      setCreateLivenessApiData(json);
      setLoading(false);
    } catch (error) {
      handleError({
        state: "SERVER_ERROR",
        message: "Failed to fetch when createliveness",
      });
    }
  };

  useEffect(() => {
    const language = i18n.language;
    setLanguage(extractLanguageCode(language));
    fetchCreateLiveness();
  }, []);

  const handleSuccess = (data) => {
    setResult({
      completed: true,
      ok: true,
    });

    dispatch({ type: "awsLiveness", value: data });

    setTimeout(() => {
      handleNextStep();
    }, 2000);
  };

  const handleFailure = () => {
    setResult({
      completed: true,
      ok: false,
    });

    fetchCreateLiveness();

    setTimeout(() => {
      setResult({
        completed: false,
        ok: false,
      });
    }, 2000);
  };

  const fetchApi = async () => {
    try {
      const response = await fetch(
        `${API_URL}/get_face_liveness_response/${createLivenessApiData.SessionId}`,
        {
          headers: new Headers({
            Authorization: `Bearer ${acessToken}`,
          }),
        }
      );

      return response;
    } catch (error) {
      handleError({
        state: "SERVER_ERROR",
        message: "Failed to fetch when getting liveness",
      });
      return false;
    }
  };

  const handleResponse = async (response) => {
    const data = await response.json();

    return data;
  };

  const handleAnalysisComplete = async () => {
    const response = await fetchApi();

    if (!response) {
      handleFailure();
      return;
    }

    const data = await handleResponse(response);

    if (data.Confidence < 75) {
      handleFailure();
    } else {
      handleSuccess(data);
    }
  };

  const handleRetry = () => {
    fetchCreateLiveness();
    setLoading(true);
    setTimeout(() => {
      setLoading(false);
    }, 1000);
  };

  return (
    <div className="w-full flex flex-col align-center justify-between flex-grow text-center lg:px-20 z-10">
      {result.completed ? (
        <>
          <p className="text-lg md:text-xl">{t("result")}</p>
          {result.ok ? (
            <>
              <CheckIcon />
              <p className="text-lg md:text-xl">{t("redirectMessage")}...</p>
            </>
          ) : (
            <>
              <CancelIcon />
              <p className="text-lg md:text-xl">{t("retryMessage")}...</p>
            </>
          )}
        </>
      ) : loading ? (
        <Loader className="self-center" />
      ) : (
        <ThemeProvider>
          <FaceLivenessDetector
            sessionId={createLivenessApiData.SessionId}
            region="us-east-1"
            onAnalysisComplete={handleAnalysisComplete}
            displayText={FaceLivenessDictionary[language]}
            onError={handleError}
            components={{
              ErrorView: ({ children }) => {
                return (
                  <Flex
                    justifyContent="center"
                    alignItems="center"
                    width="100%"
                    height="100%"
                  >
                    <Flex
                      backgroundColor="white"
                      direction="column"
                      justifyContent="center"
                      padding="32px"
                    >
                      {children}
                      <Button
                        maxWidth="120px"
                        alignSelf="center"
                        onClick={handleRetry}
                      >
                        {t("retry")}?
                      </Button>
                    </Flex>
                  </Flex>
                );
              },
            }}
          />
        </ThemeProvider>
      )}
    </div>
  );
};

export default FaceLiveness;

Console log output

No console error, the request to create the session ID is OK.

Additional information and screenshots

LivenessError

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (15 by maintainers)

Most upvoted comments

@gary-hodgson-infotrack, thanks for the testing and response here. It may be that this is a Firefox specific issue, but we’re going to try and reproduce this internally and follow up.