Download link: https://addons.mozilla.org/firefox/addon/reload-on-idle/
Reloads specified tabs on idle to reduce memory usage.
Reloads specified tabs on idle to reduce memory usage.
License: Mozilla Public License 2.0
Download link: https://addons.mozilla.org/firefox/addon/reload-on-idle/
Reloads specified tabs on idle to reduce memory usage.
MozillaのAPIリファレンスを読んでいて気がついたのですが、
このアドオンは次の3つのAPIを使えばWebExtensions化できそうです:
大きな判定処理のフローとしては、
Idle API
を通じて取得するTabs API
を通じて各タブにリロードをかけるという流れです。この判定処理を、Alarms API
を使って背後で定期的に立ち上げれば、
今のXPCOMベースのアドオンとほぼ同等の機能性を実現できるのでは、と考えています。
言葉の説明だけだと分かりにくいので、上の処理の骨組だけを実際に組み立ててみました:
background.js
function reloadTabs() {
browser.tabs.query({})
.then((tabs) => {
for (let tab of tabs) {
browser.tabs.reload(tab.id);
}
});
};
/**
* Check if the computer is in idle state
*/
browser.alarms.onAlarm.addListener((alarm) => {
browser.idle.queryState(120) // 2 min
.then((info) => {
if (info === 'idle') {
reloadTabs();
}
});
});
/**
* Create a periodic alarm
*/
browser.alarms.create("idle-reload-alarm", {
periodInMinutes: 0.5 // 30 sec
});
アドオンの外装を作って、以上のコードをFirefox実機で動かしてみましたが、
2分間なにも操作をしないと、自動的にタブのリロードが走るところまで確認できました。
どこまで細かい機能性を再現できるかですが、WebExtensionsのAPI仕様を読む限り、
次の3つのオプションは問題なく対応できそうです:
tabs.Tab.url
で判定tabs.Tab.status
で判定ただ、次の機能は対応するAPIが見つからなかったです:
また、WebExtensionsのIdle APIだと休眠判定できる最小の時間間隔が「15秒」のようです。
実際に、browsers.idle.queryState(10)
を実行すると次のエラーがでます:
(ただし、数秒間隔で自動リロードするニーズがあるかはよく分かっていません)
@piroor 以上の方針についてどう思われますか?
大きな見落としがなさそうなら、この方向性で少し取り組んでみたいと思います。
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.