chrome extension API for refreshing the page

前端 未结 6 1297
我寻月下人不归
我寻月下人不归 2020-12-14 16:54

Is there an API to programmatically refresh the current tab from inside a browser action button? I have background page configured, which attaches a listener via:

         


        
6条回答
  •  星月不相逢
    2020-12-14 17:32

    if you want to reload all the tabs which have loaded completely and are active in their window

    chrome.tabs.query({status:'complete'}, (tabs)=>{
    tabs.forEach((tab)=>{
        if(tab.url){
            chrome.tabs.update(tab.id,{url: tab.url});
         }
        });
    });
    

    you can change the parameter object to fetch only active tabs as {status:'complete', active: true} refer to query api of chrome extensions

    Reason for not using chrome.tabs.reload :

    If the tab properties especially the tab.url have not changed, tab does not reload. If you want to force reload every time, it is better to update the tab URL with its own tab.url which sends the event of the change in property and tab automatically reloads.

提交回复
热议问题