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

1.2k views Asked by At

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

There are 1 answers

0
asdjfiasd On

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();
    }
});