Refined-github: Promise canceled error when logged out

Created on 23 Oct 2017  ·  9Comments  ·  Source: sindresorhus/refined-github

Visit a user repository, e.g. https://github.com/sindresorhus while logged out and you'll get the following exception:

Uncaught (in promise) CancelError: Promise was canceled
    at PCancelable.cancel (chrome-extension://pfnempognmilfkflbpbfmcllgmmlcdal/content.js:2513:51)
    at requestAnimationFrame (chrome-extension://pfnempognmilfkflbpbfmcllgmmlcdal/content.js:1597:84)

If you're logged in, the error does not occur.

Same error occurs on the login screen itself as well.

bug help wanted

Most helpful comment

Logged out mode is not supported at all

All 9 comments

Logged out mode is not supported at all

@bfred-it I understand logged out mode is not supported, but should we really be throwing an error? I thought we had code that essentially disabled the entire extension if we were logged out? I see now that at least part of it is commented out.
https://github.com/sindresorhus/refined-github/blob/master/src/content.js#L517-L521

Refer to https://github.com/sindresorhus/refined-github/pull/592#issuecomment-314098650

If you're able to check the login status without breaking/slowing down anything you're welcome to do it (so we can also completely remove the commented out code)

Can we leverage body.logged-out?

You can try

Logged out mode is not supported at all

@bfred-it Currently the extension still works even when logged out. But errors out a lot as discussed above. To stop doing that, this commit was made, but was regressed by #592 (comment), and temporarily disabled in this commit, which is still in the codebase.

The reason is that, the DOM might not be completely ready by the time init() is called. This behavior is inconsistent in the same browser too. You can't predict weather the DOM would be ready by the time content.js has started executing. The reason content.js#445 works is that <html> will get its DOM reference before any other thing and is readily available.

So, querying for meta[user-login] or body.logged-out might return null. And now all the DOM operations of refined-github are almost made async with safeXXX() methods, but we have to check if the user is logged in synchronously to be able to stop from proceeding further.

One way of doing this can be to make init() asynchronous and await safeElementReady('body');

async function init() {
    await safeElementReady('body');
    if (document.body.classList.contains('logged-out')) {
        return;
    }

    // Only when user is logged in...
}

init();

which would violate

If you're able to check the login status without breaking/slowing down anything you're welcome to do it

and #592 (comment).


Finally, RG is pretty broke when the user is not logged in. So, it pretty sure be fixed to stop something like this issue, and the following from happening.

image

As always, open to any other suggestions or comments!

All your points are correct.

However, the reason why init exists outside onDomReady is that those features either rely on global event delegation or, more importantly, are based on safeElementReady, which waits for an element to appear in the dom hopefully before the first paint.

Waiting for body might not be that big of a deal, since it should appear long before any other element anyway, which should wait a few more milliseconds.

It’s worth a try. It succeeds if you don’t see the Trending link added after the first paint.

The only concern is that body is a magic element and the browser might return it before it’s actually parsed from the HTML, so keep that in mind should you want to try.

It’s worth a try.

Already tested it and works fine for me.

The only concern is that body is a magic element and the browser might return it before it’s actually parsed from the HTML.

We only need to check if the logged-out class exists. 🤷‍♂️

PR it then 😃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MilesBHuff picture MilesBHuff  ·  3Comments

olso picture olso  ·  3Comments

hkdobrev picture hkdobrev  ·  3Comments

hkdobrev picture hkdobrev  ·  3Comments

pawelad picture pawelad  ·  3Comments