violentmonkey: [BUG] `GM.xmlHttpRequest()` returns non-200 response

Sequence of actions:

  1. Install GitHub Star History userscript
  2. Visit https://github.com/violentmonkey/violentmonkey (or any repo) with script active in Violentmonkey
  3. Observe in console that insertStarHistory() failed to fetch image

Problem:

GitHub Star History ⭐.user.js:416 Error loading star history chart: Error: Failed to fetch image at insertStarHistory (GitHub Star History ⭐.user.js:391:19)

Expected result:

Return 200 instead of some abort obj as observed when response logging is added to the function, like Tampermonkey successfully does when running the same function in Chrome, Edge, Vivaldi, Firefox, Opera, Ghost, QQ & Whale

Devtools console contents:

When response logging is added:

image

Environment:

  • OS: Windows
  • Browser: Vivaldi Version 6.6.3271.57 (Official Build) (64-bit) (I don’t use VM/Vivaldi, but a user reported the issue in this env, so that’s where I confirmed his suspicion the function doesn’t work)
  • Violentmonkey Version: 2.18.0

About this issue

  • Original URL
  • State: closed
  • Created 3 months ago
  • Comments: 42 (16 by maintainers)

Commits related to this issue

Most upvoted comments

I didn’t value my life for a long time so I didn’t know when to stop and got myself in situations where I nearly died several times.

You’re looking at the awaited result i.e. await GM.xmlHttpRequest().

To see the returned result of the function you should look at GM.xmlHttpRequest(). You’ll see that in the specification it’s undefined, in Violentmonkey it’s a control object with abort inside, in Tampermonkey it’s Promise with abort inside.

You can’t use await anywhere except Tampermonkey if you want your script to be compatible with other specification-compliant managers.

You can use the same approach you’ve already used in your updateCheck().

You can also combine it with the standard promisification technique:

const res = await new Promise((resolve, reject) => GM.xmlHttpRequest({onload: resolve, onerror:reject}))

so it would be wise to avoid this mindset and instead try to catch up with how they implement things

Tampermonkey’s approach is not always wise.

if you also want to become a standard one day

But we don’t.