Tom Wojcik personal blog

How to find the relevant attachment in Sentry, if there's no searchbar?

☕️ 1 min read

As of today, Sentry is missing the search option in attachments page. There’s an open issue for it on GitHub

https://github.com/getsentry/sentry/issues/48680

but I doubt this feature will be implemented anytime soon, since this repo already has 2.3k issues. But there’s a workaround, a simple script that:

  1. Searches the current page for the specified text.
  2. If the text is found, alerts you and stops the script.
  3. If the text is not found, clicks the “Next” button to load the next page and repeats the search.

The JavaScript Script

Here’s the script you can paste into the Chrome console:

(function() {
    const searchText = '<your-attachment-name>';
    const nextButtonSelector = '[aria-label="Next"]';

    // Function to search for the text on the current page
    function searchAndNavigate() {
        if (document.body.innerText.includes(searchText)) {
            alert(`Found: ${searchText}`);
            return;
        }

        const nextButton = document.querySelector(nextButtonSelector);
        if (nextButton) {
            nextButton.click();
            setTimeout(searchAndNavigate, 3000); // Wait 3 seconds for the next page to load
        } else {
            alert("Next button not found or no more pages.");
        }
    }

    searchAndNavigate();
})();

Using the Script

From the attachments page in Sentry, in the event you’re interested in

  1. Open Chrome Developer Tools by pressing F12 or Ctrl+Shift+I.
  2. Navigate to the Console tab.
  3. In the script, replace searchText with the expected value.
  4. Paste the script into the console and press Enter. (you might need to type allow pasting first to disable the “copy-paste unknown code” protection)

The script will then start searching for the specified text on the current page. If it doesn’t find the text, it will navigate to the next page and continue the search. Once it’s found, it will alert you and stop searching.