Skip to content

Make script work for safari - #125

Open
svalencia014 wants to merge 3 commits into
WazeDev:masterfrom
svalencia014:master
Open

svalencia014 wants to merge 3 commits into
WazeDev:masterfrom
svalencia014:master

Conversation

@svalencia014

Copy link
Copy Markdown

Summary

This PR improves Safari compatibility and startup reliability for URC-E by fixing Google Sheets request failures, improving fallback behavior, and making error diagnostics actionable instead of generic.

Problem

On Safari, Google Sheets API calls were intermittently failing with 403 errors due to blocked requests from referer <empty>.

This caused:

  • startup warnings for auto-switch and restrictions data
  • generic or blank error popups
  • difficult troubleshooting due to low-quality error output

What changed

  • Updated userscript metadata:
    • switched WazeWrap require URL to update.greasyfork.org endpoint
    • Added request error normalization helper:
    • formats request failures with status, status text, URL, and parsed API error message when available
  • Added Google Sheets transport fallback:
    • primary path remains GM_xmlhttpRequest
    • when Safari-style referer-blocked 403 is detected, retries via page-context fetch
    • strips forbidden Referer header before fetch retry
  • Improved initialization resilience:
    • auto-switch and restrictions startup loaders now fail open with warnings instead of failing initialization
  • Improved error reporting:
    • fixed error parsing condition in handleError
    • includes Details text in generic error popup when available
    • avoids Details: [object Object] by serializing/normalizing object errors

Why this approach

  • Keeps existing behavior for browsers where GM_xmlhttpRequest works normally.
  • Adds Safari-specific fallback only when required.
  • Preserves core script functionality even when optional startup datasets are unavailable.
  • Provides clearer diagnostics for maintainers and users.

User impact

  • Reduced startup failures on Safari.
  • Fewer generic/blank error popups.
  • Better warning and error messages for debugging.
  • Comment list and translation loading become more robust under API/network edge cases.

Copilot AI review requested due to automatic review settings April 1, 2026 13:44

Copilot AI left a comment

Copy link
Copy Markdown

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 aims to improve Safari compatibility and overall startup reliability for the WME URComments-Enhanced (URC-E) userscript by adding a fallback transport for Google Sheets requests and by improving error normalization/diagnostics.

Changes:

  • Updated userscript metadata (version bump, switched WazeWrap @require URL to the update.greasyfork.org endpoint).
  • Added formatXhrError plus a requestWithReferrerFallback wrapper that retries certain 403 “referer ” failures via page-context fetch.
  • Adjusted initialization behavior to fail open for optional startup datasets (auto-switch and restrictions), and improved error display to include actionable “Details”.

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

Comment thread WME-URComments-Enhanced.js Outdated
Comment thread WME-URComments-Enhanced.js Outdated
Comment on lines +4498 to 4502
if (errMessage.includes('|')) {
const [reason, version] = errMessage.split('|');
if ((reason === 'updateRequired') || (reason === 'spreadsheetUpdateRequired')) {
const scriptLink = createElem('a', {
href: _IS_BETA_VERSION ? dec(_BETA_DL_URL) : _PROD_DL_URL, target: '_blank', textContent: _IS_BETA_VERSION ? dec(_BETA_DL_URL) : _PROD_DL_URL

Copilot AI Apr 1, 2026

Copy link

Choose a reason for hiding this comment

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

handleError now branches on errMessage.includes('|'), but only renders UI inside that branch when the prefix is updateRequired| or spreadsheetUpdateRequired|. Since newly introduced messages (e.g., formatXhrError uses | separators) can contain |, this can produce an empty error UI. Make the condition more specific (e.g., check startsWith('updateRequired|')/startsWith('spreadsheetUpdateRequired|')), or fall back to the generic error rendering when the split reason is unrecognized.

Copilot uses AI. Check for mistakes.
svalencia014 and others added 2 commits April 1, 2026 09:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@dalverson

Copy link
Copy Markdown
Member

Do you have any ideas why the original code would fail only some of the time with Safari?
Would the original code work if the referrer header were left out? Is it even needed?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants