replayCurrentUrl.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import {useMemo} from 'react';
  2. import * as Sentry from '@sentry/react';
  3. import {useReplayContext} from 'sentry/components/replays/replayContext';
  4. import TextCopyInput from 'sentry/components/textCopyInput';
  5. import {Tooltip} from 'sentry/components/tooltip';
  6. import {t} from 'sentry/locale';
  7. import getCurrentUrl from 'sentry/utils/replays/getCurrentUrl';
  8. function ReplayCurrentUrl() {
  9. const {currentTime, replay} = useReplayContext();
  10. const replayRecord = replay?.getReplay();
  11. const frames = replay?.getNavigationFrames();
  12. const url = useMemo(() => {
  13. try {
  14. return getCurrentUrl(replayRecord, frames, currentTime);
  15. } catch (err) {
  16. Sentry.captureException(err);
  17. return '';
  18. }
  19. }, [replayRecord, frames, currentTime]);
  20. if (!replay || !url) {
  21. return (
  22. <TextCopyInput size="sm" disabled>
  23. {''}
  24. </TextCopyInput>
  25. );
  26. }
  27. if (url.includes('[Filtered]')) {
  28. return (
  29. <Tooltip
  30. title={t(
  31. 'Warning! This URL contains content scrubbed by our PII filters and may no longer be valid.'
  32. )}
  33. >
  34. <TextCopyInput size="sm">{url}</TextCopyInput>
  35. </Tooltip>
  36. );
  37. }
  38. return <TextCopyInput size="sm">{url}</TextCopyInput>;
  39. }
  40. export default ReplayCurrentUrl;