
Research
/Security News
npm Author Qix Compromised via Phishing Email in Major Supply Chain Attack
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
scheduler-polyfill
Advanced tools
This is a polyfill for the Prioritized Task Scheduling API. Documentation can be found on MDN.
The polyfill includes implementations of Scheduler
, exposed through
self.scheduler
, as well as TaskController
and TaskPriorityChangeEvent
classes.
scheduler.postTask()
The implementation uses a combination of setTimeout
, MessageChannel
, and
requestIdleCallback
to implement task scheduling, falling back to setTimeout
when other APIs are not available.
The polyfill, like the native implementation, runs scheduler
tasks in
descending priority order ('user-blocking'
> 'user-visible'
>
'background'
). But there are some differences in the relative order of
non-scheduler
tasks:
"background"
tasks are scheduled using requestIdleCallback
on browsers
that support it, which provides similar scheduling as scheduler
. For
browsers that don't support it, these tasks do not have low/idle event loop
priority.
"user-blocking"
tasks have the same event loop scheduling prioritization as
"user-visible"
(similar to setTimeout()
), meaning these tasks do not have
a higher event loop priority.
scheduler.yield()
The polyfill does not support priority or signal
inheritance,
so all continuations are scheduled with "user-visible"
continuation priority.
The scheduling behavior of this depends on whether the browser supports
scheduler.postTask()
(i.e. older Chrome versions):
For browsers that support scheduler.postTask()
, scheduler.yield()
is
polyfilled with "user-blocking"
scheduler.postTask()
tasks. This means
they typically have a higher event loop priority than other tasks
(consistent with yield()
), but they can be interleaved with other
"user-blocking"
tasks.
On browsers that don't support scheduler.postTask()
, the same event loop
prioritization as the postTask()
polyfill applies (see above), but
continuations run between "user-blocking"
and "user-visible"
tasks.
A browser that supports ES6 is required for this polyfill.
npm install scheduler-polyfill
Import to populate the task-scheduling global variables, if not already available in the executing browser:
import 'scheduler-polyfill';
<script src="https://unpkg.com/scheduler-polyfill"></script>
git clone https://github.com/GoogleChromeLabs/scheduler-polyfill
cd scheduler-polyfill
npm i
npm test # Tests should pass
npm run build # Outputs minified polyfill to dist/
<script src="/path_to_polyfill/scheduler-polyfill.js"></script>
FAQs
Polyfill of self.scheduler API
We found that scheduler-polyfill demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
npm author Qix’s account was compromised, with malicious versions of popular packages like chalk-template, color-convert, and strip-ansi published.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.