Skip to content

Clean up and improve non-gitea js error filter#37148

Merged
silverwind merged 5 commits intogo-gitea:mainfrom
silverwind:filter-extension-errors
Apr 9, 2026
Merged

Clean up and improve non-gitea js error filter#37148
silverwind merged 5 commits intogo-gitea:mainfrom
silverwind:filter-extension-errors

Conversation

@silverwind
Copy link
Copy Markdown
Member

@silverwind silverwind commented Apr 8, 2026

  1. Filter out errors that contain chrome-extension:// etc protocols
  2. Extract filtering into its own function and test it
  3. Fix the window.config.assetUrlPrefix mock, guaranteed to end with /assets
  4. Remove useless ?? and ?. for properties that always exist

This PR was written with the help of Claude Opus 4.6

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 8, 2026
Explicitly detect and filter errors originating from browser extensions
by checking for extension URL schemes (chrome-extension://,
moz-extension://, safari-extension://, safari-web-extension://) in the
error's filename and stack trace. This prevents unrelated extension
errors from being shown to users.

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@silverwind silverwind changed the title Filter out browser extension errors from error handler Filter out browser extension errors from global js error handler Apr 8, 2026
@silverwind
Copy link
Copy Markdown
Member Author

silverwind commented Apr 8, 2026

There is a similar condition below this one with the same purpose. I'll check if it makes sense to retain both conditions (defense in depth). Edit: Updated.

Unify browser extension and asset URL checks into a single isGiteaError
function. Filter non-Gitea errors in all modes, not just production.
Add tests and fix vitest assetUrlPrefix to use realistic value.

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@silverwind silverwind changed the title Filter out browser extension errors from global js error handler Clean up and improve non-gitea js error filter Apr 8, 2026
@silverwind
Copy link
Copy Markdown
Member Author

@bircni if you could test this for your Safari error it would be great. If you can post the full stack trace from the browser console, it would be even greater.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the frontend global error handler’s “non-Gitea JS error” filtering to reduce user-facing noise from browser extensions/external scripts, and updates tests/mocks accordingly.

Changes:

  • Introduces an isGiteaError() helper to centralize filtering logic (including extension-protocol detection).
  • Updates processWindowErrorEvent() to use the new filter and simplifies config access.
  • Makes the Vitest window.config mock more realistic and adds unit tests for the new filter helper.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
web_src/js/vitest.setup.ts Adjusts window.config.assetUrlPrefix mock to '/assets' to better match runtime.
web_src/js/modules/errors.ts Adds isGiteaError() and switches global error processing to use it.
web_src/js/modules/errors.test.ts Adds targeted unit tests for isGiteaError().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread web_src/js/modules/errors.ts
Comment thread web_src/js/modules/errors.ts
Comment thread web_src/js/modules/errors.ts
Comment thread web_src/js/modules/errors.test.ts
Address review feedback: reject errors where filename points to a
non-Gitea URL (not matching asset prefix or page origin). Add tests
for external and same-origin inline script filenames.

Co-Authored-By: Claude (Opus 4.6) <noreply@anthropic.com>
@wxiaoguang wxiaoguang added the backport/v1.26 This PR should be backported to Gitea 1.26 label Apr 9, 2026
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 9, 2026
@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 9, 2026
@silverwind silverwind enabled auto-merge (squash) April 9, 2026 08:34
@silverwind silverwind merged commit 0914a44 into go-gitea:main Apr 9, 2026
26 checks passed
@silverwind silverwind deleted the filter-extension-errors branch April 9, 2026 08:36
@GiteaBot GiteaBot added this to the 1.27.0 milestone Apr 9, 2026
GiteaBot pushed a commit to GiteaBot/gitea that referenced this pull request Apr 9, 2026
1. Filter out errors that contain `chrome-extension://` etc protocols
2. Extract filtering into its own function and test it
3. Fix the `window.config.assetUrlPrefix` mock, guaranteed to end with
`/assets`
4. Remove useless `??` and `?.` for properties that always exist

Co-authored-by: Claude (Opus 4.6) <noreply@anthropic.com>
@GiteaBot GiteaBot added the backport/done All backports for this PR have been created label Apr 9, 2026
silverwind added a commit that referenced this pull request Apr 9, 2026
Backport #37148 by @silverwind

1. Filter out errors that contain `chrome-extension://` etc protocols
2. Extract filtering into its own function and test it
3. Fix the `window.config.assetUrlPrefix` mock, guaranteed to end with
`/assets`
4. Remove useless `??` and `?.` for properties that always exist

---
This PR was written with the help of Claude Opus 4.6

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Claude (Opus 4.6) <noreply@anthropic.com>
zjjhot added a commit to zjjhot/gitea that referenced this pull request Apr 10, 2026
* main:
  Make Markdown fenced code block work with more syntaxes (go-gitea#37154)
  Remove unneeded doctor sub-commands (go-gitea#37156)
  Report structurally invalid workflows to users (go-gitea#37116)
  Replace `rollup-plugin-license` with `rolldown-license-plugin` (go-gitea#37130)
  Clean up and improve non-gitea js error filter (go-gitea#37148)
@bircni
Copy link
Copy Markdown
Member

bircni commented Apr 14, 2026

@bircni if you could test this for your Safari error it would be great. If you can post the full stack trace from the browser console, it would be even greater.

works somehow it is because of 1pw lol

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/done All backports for this PR have been created backport/v1.26 This PR should be backported to Gitea 1.26 lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants