replayCurrentUrl.tsx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import {useMemo} from 'react';
  2. import * as Sentry from '@sentry/react';
  3. import ExternalLink from 'sentry/components/links/externalLink';
  4. import Link from 'sentry/components/links/link';
  5. import {useReplayContext} from 'sentry/components/replays/replayContext';
  6. import TextCopyInput from 'sentry/components/textCopyInput';
  7. import {Tooltip} from 'sentry/components/tooltip';
  8. import {t, tct} from 'sentry/locale';
  9. import getCurrentUrl from 'sentry/utils/replays/getCurrentUrl';
  10. import useOrganization from 'sentry/utils/useOrganization';
  11. import useProjects from 'sentry/utils/useProjects';
  12. import {normalizeUrl} from 'sentry/utils/withDomainRequired';
  13. function ReplayCurrentUrl() {
  14. const {currentTime, replay} = useReplayContext();
  15. const replayRecord = replay?.getReplay();
  16. const frames = replay?.getNavigationFrames();
  17. const projId = replayRecord?.project_id;
  18. const {projects} = useProjects();
  19. const projSlug = projects.find(p => p.id === projId)?.slug ?? undefined;
  20. const organization = useOrganization();
  21. const url = useMemo(() => {
  22. try {
  23. return getCurrentUrl(replayRecord, frames, currentTime);
  24. } catch (err) {
  25. Sentry.captureException(err);
  26. return '';
  27. }
  28. }, [replayRecord, frames, currentTime]);
  29. if (!replay || !url) {
  30. return (
  31. <TextCopyInput aria-label={t('Current URL')} size="sm" disabled>
  32. {''}
  33. </TextCopyInput>
  34. );
  35. }
  36. if (url.includes('[Filtered]')) {
  37. return (
  38. <Tooltip
  39. title={tct(
  40. "Funny looking URL? It contains content scrubbed by our [filters] and may no longer be valid. This is to protect your users' privacy. If necessary, you can turn this off in your [settings].",
  41. {
  42. filters: (
  43. <ExternalLink href="https://docs.sentry.io/product/data-management-settings/scrubbing/server-side-scrubbing/">
  44. {'Data Scrubber'}
  45. </ExternalLink>
  46. ),
  47. settings: projSlug ? (
  48. <Link
  49. to={normalizeUrl(
  50. `/settings/${organization.slug}/projects/${projSlug}/security-and-privacy/`
  51. )}
  52. >
  53. {'Settings, under Security & Privacy'}
  54. </Link>
  55. ) : (
  56. 'Settings, under Security & Privacy'
  57. ),
  58. }
  59. )}
  60. isHoverable
  61. >
  62. <TextCopyInput aria-label={t('Current URL')} size="sm">
  63. {url}
  64. </TextCopyInput>
  65. </Tooltip>
  66. );
  67. }
  68. return (
  69. <TextCopyInput aria-label={t('Current URL')} size="sm">
  70. {url}
  71. </TextCopyInput>
  72. );
  73. }
  74. export default ReplayCurrentUrl;