如何在加载后延迟 Webview 页面的警报?

How can you delay alerts for Webview pages after loading?

我有以下内容:

import React from 'react';
import { View, ActivityIndicator } from 'react-native';
import { WebView } from 'react-native-webview';

export default function Links() { 
  function LoadingIndicatorView() {
    return (
      <View style={styles.hubLoading}>
        <ActivityIndicator color='#009b88' size='large' />
      </View>
    )
  }

  const runFirst = 'window.alert("You will see this just before the webpage loads"); true;';
  const runAfterTenSecs = 'window.alert("You have been on this page for 10 seconds"); true;';

  return <WebView 
    source={{ uri: https://google.com }}
    renderLoading={LoadingIndicatorView}
    startInLoadingState={true}
    originWhitelist={['*']}
    javaScriptEnabled={true}
    onMessage={() => {}}
    injectedJavaScript={runFirst}
  />;
}

runAfterTenSecs 当前未使用。我可以对其进行哪些更改,或 runFirst,以在 Webview 加载十秒后产生警告“您已在此页面上停留 10 秒”的预期结果?

您可以使用setTimeout延迟执行。

window.alert("You will see this just before the webpage loads");
setTimeout(`window.alert("You have been on this page for 10 seconds")`, 10000);