soscripted / sox

Stack Overflow Extras: a userscript for the Stack Exchange websites to add a bunch of optional toggle-able features
http://stackapps.com/q/6091/
MIT License
72 stars 15 forks source link

error loading the feature "Appearance-markEmployees" #454

Closed IzzySoft closed 3 years ago

IzzySoft commented 4 years ago

Describe the bug Not sure what is affected, but while looking for the reason parts of the timer script don't work I found the following in the browser console:

SOX errors logged in console

SOX: There was an error loading the feature "Appearance-markEmployees". Please raise an issue on GitHub, and copy the following error log:
TypeError: el.href.contains is not a function  sox.common.js:38:7
    sox.error file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/sox.common.js:38:7
    init file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/sox.user.js:171:13
    sox.ready/< file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/sox.common.js:79:11
    l file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/jquery-3.3.1.min.js:2:29373
    a/</c< file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/jquery-3.3.1.min.js:2:29677
SOX: There was an error loading the feature "Editing-inlineEditorEverywhere". Please raise an issue on GitHub, and copy the following error log:
TypeError: sox.Stack.using is not a function  sox.common.js:38:7
    sox.error file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/sox.common.js:38:7
    init file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/sox.user.js:171:13
    sox.ready/< file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/sox.common.js:79:11
    l file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/jquery-3.3.1.min.js:2:29373
    a/</c< file:///***/gm_scripts/Stack_Overflow_Extras_(SOX)/jquery-3.3.1.min.js:2:29677

Probably related, preceding the error:

Warning: flattenChildren(...): Encountered two children with the same key, `70596`. Child keys must be unique; when two children share a key, only the first child will be used.
    in ul (created by d)
    in div (created by d)
    in d
    in div
    in div  react-dom.js:18238:9

Environment SOX version: 2.6.14 DEV Platform: Linux Mint 18.3, Waterfox 52.2.14, Greasemonkey (last pre-WE version)


Features Enabled

["Appearance-addAuthorNameToInboxNotifications","Appearance-alignBadgesByClass","Appearance-colorAnswerer","Appearance-dragBounty","Appearance-highlightQuestions","Appearance-isQuestionHot","Appearance-markEmployees","Appearance-metaChatBlogStackExchangeButton","Appearance-scrollToTop","Appearance-spoilerTip","Appearance-tabularReviewerStats","Appearance-topAnswers","Appearance-unspoil","Appearance-addTimelineAndRevisionLinks","Appearance-showTagWikiLinkOnTagPopup","Comments-autoShowCommentImages","Comments-commentReplies","Comments-commentShortcuts","Comments-confirmNavigateAway","Comments-copyCommentsLink","Comments-moveBounty","Comments-hiddenCommentsIndicator","Comments-onlyShowCommentActionsOnHover","Editing-addSBSBtn","Editing-editComment","Editing-editReasonTooltip","Editing-findAndReplace","Editing-kbdAndBullets","Editing-titleEditDiff","Editing-inlineEditorEverywhere","Flags-flagOutcomeTime","Flags-flagPercentages","Flags-flagPercentageBar","Sidebar-hideCommunityBulletin","Sidebar-hideJustHotMetaPosts","Sidebar-hideHireMe","Sidebar-hideLoveThisSite","Sidebar-linkedToFrom","Chat-chatEasyAccess","Chat-replyToOwnChatMessages","Chat-renameChat","Voting-betterCSS","Voting-stickyVoteButtons","Voting-disableVoteButtons","Extras-linkedPostsInline","Extras-quickAuthorInfo","Extras-sortByBountyAmount","Extras-warnNotLoggedIn","Extras-hideCertainQuestions","Extras-showMetaReviewCount","Extras-copyCode","Extras-dailyReviewBar","Extras-openLinksInNewTab"]
double-beep commented 4 years ago

In which question did you encounter this error? Or do you encounter this error in every question?

IzzySoft commented 4 years ago

Every question I tried on SoftwareRecs.SE and Android.SE.

apologies for the other two "pings": those reports belonged to another project I reported a problem simultaneously to…

shu8 commented 4 years ago

I can't reproduce this on those sites either, please could you check if you get this bug if you temporarily disable the other timer script you have installed?

IzzySoft commented 4 years ago

I did that already before reporting (disabled all other SE scripts), the error remains in the console. Just checked again now, still there.

Just reported this as I found it in the console (and the message asked to report). Nothing seems broken so far, so priority is rather low for me. Could it be some browser compatibility thing? I'm using Waterfox Classic here, as stated above – and the "classic" Greasemonkey.

double-beep commented 4 years ago

I would suggest using Tampermonkey or Violentmonkey. I recommend against using Greasemonkey. Greasemonkey 3 was great. I highly preferred it. Unfortunately, with Greasemonkey 4 (GM4), a complete rewrite required by Firefox changing to WebExtensions only, there were decisions made that make GM4 incompatible with a large number of userscripts. Of the userscripts I use for Stack Overflow, 30 of them are incompatible with GM4.

https://chat.stackoverflow.com/transcript/41570?m=47424434

IzzySoft commented 4 years ago

Thanks for the pointer, @double-beep – and let me point out again that I'm still using the non-WE Greasemonkey here (Waterfox Classic still supports XUL), so

Greasemonkey 3 was great. I highly preferred it.

Full ack. And I still do run Greasemonkey 3.17 :wink:

That said: I just upgraded to the latest SOX version (I just returned from vacation, hence my delayed answer). The error is still shown in console. Again, low prio for me – I just reported this as the log message asked me to.

shu8 commented 4 years ago

@IzzySoft This should be fixed in dev 2.6.18 now! :)

IzzySoft commented 4 years ago

Sorry to disappoint you, but I still get it with 2.6.21 here. Both, Appearance-markEmployees and Editing-inlineEditorEverywhere.

shu8 commented 4 years ago

Hmmm this is really quite weird because it's only happening for these features! I just installed Waterfox, but can't seem to find a place to get Greasemonkey 3.17 to test this on, do you know where I can install it from?

Also, please could you paste the entire console output after disabling other extensions? I just want to see if there's anything that might hint at what's going on here!

IzzySoft commented 4 years ago

Sorry for not updating; I still see the issue, but found no time to do the "big dig". Especially as disabling extensions means multiple browser restarts (yes, legacy addons), and I always have multiple tabs with open work :cry: As long as it's only something showing up in the console, it doesn't hurt me – and I miss no functionality (I'd only like to know what's always deleting my localStorage, rendering some scripts like timer useless and forcing me to copy-paste my canned comments 5 times a week – but I don't assume SOX behind that, though it seems to only affect SO sites; I don't want to disable SOX for a week to find out either :wink:)

double-beep commented 4 years ago

Can you do the following?

  1. Update to SOX latest DEV version

  2. Change line 48 with:

    return ![...el.children].filter(el => el.classList.indexOf('sox-markEmployees') > -1).length && el.href && el.href.match(/\/users\/\d+/);

  3. And line 73 with:

    anchors.filter(el => el.href.indexOf(/users/${userId}/) > -1).forEach(el => el.appendChild(logoSpan.cloneNode(true)));

Does it work now?

IzzySoft commented 4 years ago

Thanks @double-beep! Took me a little to find a file where your line numbers fitted something that looked right :laughing: sox.features.js seems to fit your line numbers (that doesn't open via GM menues).

Unfortunately, changing those lines doesn't get rid of the

errors in console.

SOX: There was an error loading the feature "Appearance-markEmployees". Please raise an issue on GitHub, and copy the following error log:
TypeError: el.classList.indexOf is not a function  sox.common.js:38:7
    sox.error Stack_Overflow_Extras_(SOX)/sox.common.js:38:7
    init Stack_Overflow_Extras_(SOX)/sox.user.js:172:13
    sox.ready/< sox.common.js:79:11
    l jquery-3.3.1.min.js:2:29373
    a/</c< jquery-3.3.1.min.js:2:29677
SOX: There was an error loading the feature "Editing-inlineEditorEverywhere". Please raise an issue on GitHub, and copy the following error log:
TypeError: sox.Stack.using is not a function  sox.common.js:38:7
    sox.error sox.common.js:38:7
    init sox.user.js:172:13
    sox.ready/< sox.common.js:79:11
    l jquery-3.3.1.min.js:2:29373
    a/</c< jquery-3.3.1.min.js:2:29677

Funny thing is both stack traces seem to be identical to the letter. So to me it's not clear where they originate. Your first one indeed was one of the two – when replacing that with null, the error is gone (but of course without enabling the feature).

double-beep commented 4 years ago

Uh, ️🤦‍♂️. Replace classList with className in L48. Apparently, classList returns a DOMTokenList, but indexOf needs a string (or an array) to work.

IzzySoft commented 4 years ago

Yes, that does the trick! One down (sox-markEmployees), one to go (Editing-inlineEditorEverywhere).

double-beep commented 4 years ago

@shu8 can we replace .contains() with .indexOf() to make markEmployees compatible with Waterfox?

@IzzySoft that's an interesting error. What's the output of !!StackExchange.using in console (should be true)? What do you get when you add sox.warn("StackExchange.using exists: " + !!sox.Stack.using + "; object: " + sox.Stack.using); after line 2240? Also, do you get any inlineEditorEverywhere error: sox.Stack.using not found warnings in console?

IzzySoft commented 4 years ago

What's the output of !!StackExchange.using in console (should be true)?

It is true.

What do you get when you add

That would be right before sox.Stack.using('inlineEditing', () => {, correct?

SOX: StackExchange.using exists: false; object: undefined

Funny thing is: I've added console.log(sox.stack); right after if (sox.Stack) { and investigated the object returned. According to console, it has a using: y(). Though I cannot tell when console does evaluate that (probably when I click for the details, which is a lot later). If I replace that with console.log(sox.stack.using); I get the expected undefined. Maybe the conditional if (sox.stack) should be replaced by if (sox.stack.using)? That (obviously) removes the error – but of course the functionality is not implemented then.

For some context: I'm a mod, so I guess my reputation is high enough to already have the inline editor. Let me check a few other sites (rep in parenthesis):

So it has nothing to do with my rep or being mod.

do you get any inlineEditorEverywhere error: sox.Stack.using not found warnings in console?

No. But with my suggested change above (replacing the conditional) I do, obviously.

double-beep commented 4 years ago

Do note that JavaScript is case-sensitive - sox.stack is not the same as sox.Stack! Also, do you get the same contains is not a function error wrt. the markEmployees feature? What's the colorAnswerer error you get?

Apparently, Waterfox is quite slow to create (or update?) the using property of the StackExchange. I suggest that you use this answer to fix this problem. More specifically:

inlineEditorEverywhere: async function() {
  // Description: Enabled inline editor on all sites
  // Written by @nicael: http://stackapps.com/questions/6216/inline-editor-regardless-of-reputation, and copied with nicael's permission

  while (!sox.Stack.using) {
    await new Promise(resolve => setTimeout(resolve, 100));
    sox.warn("Not defined");
  }
  sox.warn("Finally defined");

  if (sox.Stack) {
    $('.suggest-edit-post').removeClass('suggest-edit-post').addClass('edit-post');
    sox.Stack.using('inlineEditing', () => {
      sox.Stack.inlineEditing.init();
    });
  } else {
    sox.warn('inlineEditorEverywhere error: sox.Stack.using not found');
    sox.debug('inlineEditorEverywhere: Stack object:', sox.Stack);
  }
},

That should probably fix the problem. However, keep in mind that it's ugly, temporary and possibly not efficient.

IzzySoft commented 4 years ago

No errors anymore then, right – but for a different reason: SOX won't load anymore at all then. Looks like it gets stuck in that while loop then.

Nevermind, I can live with the current situation. I just reported the issue as SOX's debug output asked me to :wink:

shu8 commented 4 years ago

Thanks for the debugging for the first issue @double-beep and @IzzySoft!

@shu8 can we replace .contains() with .indexOf() to make markEmployees compatible with Waterfox? Yes! Thanks for finding this out :) I can make that change soon or would be happy to review a PR for it too


For the sox.Stack issue, for some reason I remember this as a Firefox issue and the whole reason why we started to use sox.Stack and not StackExchange, see https://github.com/soscripted/sox/blob/dev/sox.common.js#L52 for the 'hacky' assignment of Stack.

I can't remember what exactly was the problem with FF though, so it might be worth trying to just use StackExchange or window.StackExchange again.

Reopening though because this seems to definitely be a bug! Thanks again for the debugging :)

IzzySoft commented 4 years ago

Feel free to let me know if I should test something then!