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

Make using requestIdleCallback optional to overcome it's not being reliably called in Electron #1634

Closed
elyulka opened this issue May 28, 2019 · 7 comments

Comments

@elyulka
Copy link

@elyulka elyulka commented May 28, 2019

What version of WebTorrent?

0.103.1

What operating system and Node.js version?

Node 10.15.3, OS X 10.14.4

What browser and version? (if using WebTorrent in the browser)

Electron 4.2.2

What did you expect to happen?

requestIdleCallback must be called to perform downloading of data.

What actually happened?

It's called sometimes in unpredictable manner. Mostly not called at all.

My proposal is to make using requestIdleCallback optional. Thanks.

@lacker

This comment has been minimized.

Copy link

@lacker lacker commented Jun 7, 2019

I had a similar problem, with requestIdleCallback not existing in Chrome extensions. A hacky workaround is to do window.requestIdleCallback = f => f(); at the beginning of your application - that will just make any requestIdleCallback callbacks run immediately.

@guanzo

This comment has been minimized.

Copy link
Contributor

@guanzo guanzo commented Jun 8, 2019

Related to #1615

@stale

This comment has been minimized.

Copy link

@stale stale bot commented Sep 6, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the stale label Sep 6, 2019
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Sep 7, 2019

@lacker I'm confused why you'd need to do include window.requestIdleCallback = f => f() as we already check if requestIdleCallback exists before attempting to use it:

if (typeof window !== 'undefined' && typeof window.requestIdleCallback === 'function') {

@stale stale bot removed the stale label Sep 7, 2019
@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Sep 7, 2019

This issue should be fixed now that #1615 is merged and released as 0.107.11

@feross feross closed this Sep 7, 2019
@lacker

This comment has been minimized.

Copy link

@lacker lacker commented Sep 7, 2019

I should have been more specific. In a Chrome extension background page, requestIdleCallback does exist. However, it doesn't do anything. The callback you pass to it never gets called. I'm not totally sure why, but I did find this stack overflow page explaining it as "This function is frame-based just like rAF so it doesn't work in a nonrenderable context such as the background page." https://stackoverflow.com/questions/55461030/does-requestidlecallback-work-in-the-background-page-of-chrome-extensions

So, it doesn't seem like this change will fix the behavior in extensions, but my workaround is working fine for me so I'm fine with the status quo. Just leaving this comment here in case future people run into it.

@feross

This comment has been minimized.

Copy link
Member

@feross feross commented Sep 7, 2019

@lacker Very informative. Thanks for the comment!

@feross feross reopened this Sep 7, 2019
@feross feross closed this Sep 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.