jamesjonesmath / canvancement

Enhancements to the Canvas LMS
ISC License
215 stars 95 forks source link

import rubric — installed but "import rubric" button does nothing #57

Open meganlavengood opened 8 months ago

meganlavengood commented 8 months ago

Hey, I am very excited about this script. I don't know a ton about js but I usually feel competent enough to copy-paste JS from the internet and tweak it make it work for my needs.

I got the script running on the page using Tamperish (instead of Tamper Monkey) and the new button Import Rubric appears on the Rubrics page, but when I click it nothing happens. Here's some info from console (not totally sure which is relevant except the last bit).

[Log] [Tamperish] Injecting canvas-rubric-importer.js (script.js, line 84, x3)
[Log] Registration succeeded. Refresh page to proxy Inst-FS requests through ServiceWorker. (main-entry-c4bc4f466cfd3697.js, line 2439)
[Error] FetchEvent.respondWith received an error: TypeError: Load failed
[Error] Fetch API cannot load https://gmu.instructure.com/images/thumbnails/5114/N4JCaA7hXge0wpAdxmiGwVavp9qVC1NSI0YHGcvj.
[Error] Failed to load resource: FetchEvent.respondWith received an error: TypeError: Load failed (N4JCaA7hXge0wpAdxmiGwVavp9qVC1NSI0YHGcvj, line 0)
[Log] ReferenceError: Can't find variable: $
openDialog

I think I've seen that reference error before when using jQuery and not importing it correctly, so I added // @require http://code.jquery.com/jquery-latest.js to the header but still got the same error.

jamesjonesmath commented 8 months ago

This could be related to the jQuery upgrades that Canvas is pushing out.

I've got version 2.2.4, which is the version that was deployed on March 13 and my script is still running. Even if the JavaScript upgrade isn't affecting my script directly, it could be affecting another script that then breaks mine.

Loading the latest version of jQuery is pretty sure to break things. You need the jQuery that comes with Canvas since they have patched the ajax to automatically add the csrf token to provide authentication. Loading it from http instead of https (that may have just been a typo on your part) makes it worse since that's insecure on a page that is running secure.

Depending on how you load your jQuery, you may need to use the noConflict() to release $ back to the other software. That's my best first guess is that something removed the jQuery from $ and now it's not available. My script doesn't do that, though.

Another possibility is that the script is running before jQuery is installed. Despite Canvas guaranteeing it would be available (it hasn't always been despite the guarantee), I don't know anything about tamperish but I suspect it's something else.

There is a possibility that the other error messages blocked execution. Are you running any other scripts that use jQuery? Does your institution have any global JavaScript installed that uses jQuery? Are there any noConflicts() in places?

Go to the Rubrics page and then open the developer tools console. Try executing these commands (enter after each one)

At some point, I should rewrite this script to not rely on jQuery; it was just easier at the time as I needed their dialog box. Right now, I'm in the middle of a time-critical project and don't have time to try and track down an issue I'm not seeing. If you can do some debugging on your end and get back, that would help.

If you have other scripts, then debugging may involve turning off some of your other scripts and reloading the rubric importer. If it works with all of the other scripts disabled, then you can start turning them back on in groups until you find one that breaks it. It's possible that more than one is breaking things, so I would start by disabling all. Then turn half back on and retest. If it works, then turn on half of what's left and repeat until you find the one that's bad. If the first half broke it, then turn off half of those and test.

If the script doesn't work at all when all of your other scripts are disabled, then it could be something your institution is loading, something to do with tamperish, or that there is a problem with Canvas not making jQuery available. If it's the case of Canvas not making $ available, then disabling tamperish and running those three commands would identify that.

meganlavengood commented 8 months ago

I tried the commands above and # returned function(e,t){return new p.fn.init(e,t)} = $2. And I had 2.2.4 for my jQuery version.

I don't have any other scripts running through Tamperish. I have a Zotero extension running, but disabled it on the website. I still saw it loading in my browser extension scripts somehow. But I'm unclear on whether that could even be interfering. I'm not sure how to find out if there are other institution scripts that use jQuery, and also not sure how else to check for noConflicts(). Sorry, I am a big faker when it comes to JS and jQuery.