How can chrome app reload itself? (document.location.reload is not allowed)

こ雲淡風輕ζ 提交于 2020-01-05 02:50:22

问题


I am developing chrome app. I need to refresh it often but it is not possible by calling:

window.location.reload()

or

document.location.reload()

In console there is error message:

Can't open same-window link to "chrome-extension://dmjpjfnceeilhihfbkclnbnhjpcgcdpn/window.html"; try target="_blank".


回答1:


Instead use this:

chrome.runtime.reload();

If you have developer tools opened, they will be refreshed as well. Also it seems that if you have only opened app window and developer tools (and you closed browser itself), this will close app but will not load it back again, so you have to keep browser open (e.g. minimized).

During development you can add callback for F5 key to refresh the app:

window.addEventListener('keydown', function () {
    if (event.keyIdentifier === 'F5') {
        chrome.runtime.reload();
    }
});  


来源:https://stackoverflow.com/questions/30751939/how-can-chrome-app-reload-itself-document-location-reload-is-not-allowed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!