Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Greasemonkey #123

Closed
ROpdebee opened this issue Oct 19, 2021 · 4 comments · Fixed by #224
Closed

Support Greasemonkey #123

ROpdebee opened this issue Oct 19, 2021 · 4 comments · Fixed by #224
Assignees
Labels
enhancement New feature or request

Comments

@ROpdebee
Copy link
Owner

ROpdebee commented Oct 19, 2021

At some point we should probably add support for userscript engines which use the GM v4 API (GM.*).

https://github.com/greasemonkey/gm4-polyfill

#112

ECAU doesn't work on GreaseMonkey 3 either: https://chatlogs.metabrainz.org/libera/musicbrainz/msg/4903067/
Likely because of the unsafeWindow "feature" (because we @grant stuff, we don't get access to the real window object anymore).

@Freso
Copy link

Freso commented Oct 22, 2021

Would this also fix the script not working at all with Greasemonkey, or is that for a separate issue?

@ROpdebee
Copy link
Owner Author

Depends. If it's not working on Greasemonkey 4, I'd bet that's because of the API changes and that would be fixed by this issue. If it's not working on Greasemonkey 3 either, that'd be a separate issue 🙂

It could also be the same issue as @kellnerd faced with jQuery under GM4 (kellnerd/musicbrainz-scripts#12). Unfortunately the fix for Enhanced Cover Art Uploads wouldn't be as easy as just using a standalone version of jQuery or dropping jQuery altogether, because it needs to use MB's jQuery to enqueue the images, any other jQuery or native browser functionality doesn't seem to work. I'd need to investigate that a bit more though.

Are you using GM4? If so, I could prioritise this, but since most userscripts out there don't support GM4 either it hasn't been a priority for me so far.

@ROpdebee
Copy link
Owner Author

ROpdebee commented Oct 22, 2021

Did some testing, there are multiple problems with ECAU under GM4:

  • the run-at property is completely wrong, and the script doesn't seem to run at all. It's currently set to document-load, which doesn't seem to be a valid value for any userscript engine. I probably meant to use document-end here...
  • The fetch call to the MB API fails as it doesn't resolve the relative URL. We either need to provide document.location.origin explicitly, or use unsafeWindow.fetch which does properly resolve relative URLs.
  • MB's jQuery is indeed not available, but we can access it through unsafeWindow.$.
  • Then it fails since GM_xmlhttpRequest isn't defined, so we should include the polyfills.

Some of these possibly occur under older GM versions too.

IMO I should really add automated E2E tests before working on compatibility with all these different userscript engines and browsers. There are huge incompatibilities between all of these (see also #49, #59, #145, #75), so fixing a problem for one engine might break support for another one, and I can't test all of these combinations manually on every change. So running E2E tests in CI is pretty much a necessity to make sure we don't break any existing support when adding support for GM.

I should also note that this only applies to ECAU for now. The other scripts are possibly (likely) also incompatible, but fixing that would be part of porting those scripts to the new build system which is a long-term effort.

@Freso
Copy link

Freso commented Oct 23, 2021

Are you using GM4?

Yeah. Currently on 4.11. I’ve considered switching to one of the other engines, but when I’ve tried in the past, I’ve had to manually go around and find all "my" userscripts again and reimport them in the new one… and I just gave up on that. Maybe I’ll try again one of these days. :)

@ROpdebee ROpdebee changed the title Support Greasemonkey v4 Support Greasemonkey Nov 7, 2021
@ROpdebee ROpdebee self-assigned this Nov 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants