tabs.warmup() 编辑
To optimize system resource usage, browsers may drop GPU resources associated with tabs that the user has not accessed for a certain amount of time. If a browser has done this for a tab, then reactivating the tab (for example, when the user switches to it) may take longer than it normally would.
The tabs.warmup()
API enables an extension to start the process of rendering the resources for an inactive tab, if the extension expects that the user might switch to the tab soon. This then makes the actual tab switch faster than it would be otherwise.
Note this API does not work on discarded tabs and does not need to be called immediately prior to switching tabs. It is merely a performance improvement when the tab switch can be anticipated, such as when hovering over a button that when clicked would switch to the tab.
It is expected that this API would mostly be useful to tab management extensions.
This is an asynchronous function that returns a Promise
.
Syntax
var warming = browser.tabs.warmup(
tabId // integer
)
Parameters
tabId
integer
. ID of the tab to warm up. If the argument passed here is not an integer (in particular, if it isnull
orundefined
) thenwarmup()
will throw an exception synchronously.
Return value
A Promise
that will be fulfilled with no arguments if the tab identified by tabId
is sucessfully warmed up. If tabId
does not identify an open tab, or if warming up fails for some other reason, then the promise will be rejected with an error message.
Examples
This code adds a listener to the browserAction.onClicked
event. The listener retrieves all tabs in the current window that contain pages under "/wiki/" and warms up the first one that it finds.
function onSuccess() {
console.log("success!");
}
function onFailure(error) {
// e.g. ID of a nonexistent tab
console.error(error);
}
async function warmupMDN() {
const mdnTabs = await browser.tabs.query({
currentWindow: true,
url: "/wiki/*"
});
if (mdnTabs.length > 0) {
const warming = browser.tabs.warmup(mdnTabs[0].id);
warming.then(onSuccess, onFailure);
}
}
browser.browserAction.onClicked.addListener(warmupMDN);
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论