Google Chrome itself is rebooting, what should I do? Hot reload of Chrome extension

Browser Google Chrome They are used everywhere, and therefore everyone has heard well about the problems that occur with it. In particular, it happens to freeze completely at the most inopportune moment, which requires an immediate reboot. Next, we will tell you how to quickly and painlessly cope with such difficulties.

In contact with

Google Chrome, in addition to its advantages, is also known for how quickly it manages to fill the entire RAM. The processor is instantly loaded to capacity, and the computer begins to slow down terribly and throw notifications to the user asking for help. You can deal with the problem by simply restarting the application. That is, by closing and reopening the browser, as users usually do. But there is another way to quickly reset and restore the program.

It differs from the first in the speed of the operation. This method is not known to everyone, although it is much simpler than a manual reboot. So, in order to refresh a frozen browser, you can enter the command in the address bar chrome://restart. For greater convenience, you can save it as a bookmark and use it in critical cases. And you can do it like this:

1 . Create a bookmark of any random page;

2. Click on it right click mouse and click on the button Change»;


3. Copy the command into the line that appears with the URL subtitle chrome://restart, and in the field “ Name» Enter any convenient word or set of characters.

It’s just important not to forget that when you restart the browser, all data entered into the browser may disappear. open tabs. Therefore, before rebooting, it is advisable to make sure that as a result of the operation no important unsent comment or message will be lost.

The other day I had the desire to write a simple extension for Google Chrome. I encountered a problem that after changes in the extension code, the browser does not reload it automatically. This makes development very difficult, because... after each Cmd-S in the editor, you have to click “Reload” in the list of extensions, and then also refresh the page to restart the content scripts.


After some research, it turned out that Chrome provides all the necessary APIs to implement such functionality for its extension yourself.


The ready-made embedded solution is located at github.com/xpl/crx-hotreload, and in this article I will tell you how it is implemented.


We use the File and Directory Entries API to recursively get a list of files in a folder:


const filesInDirectory = dir => new Promise(resolve => dir.createReader().readEntries(entries => Promise.all(entries.filter(e => e.name !== ".").map(e => e.isDirectory ? filesInDirectory (e) : new Promise (resolve => e.file (resolve))) .then (files => .concat (...files)).then (resolve)))

We generate a “composite” timestamp from all timestamps of the received files and their names:


const timestampForFilesInDirectory = dir => filesInDirectory(dir).then(files => files.map(f => f.name + f.lastModifiedDate).join())

Thus, we can detect not only changes in files, but also their deletion/adding/renaming.


Watchdog checking for changes every 1000ms:


const watchChanges = (dir, lastTimestamp) => ( timestampForFilesInDirectory (dir).then (timestamp => ( if (!lastTimestamp || (lastTimestamp === timestamp)) ( setTimeout (() => watchChanges (dir, timestamp), 1000) // retry after 1s ) else ( reload () ) )) )

const reload = () => ( chrome.tabs.query (( active: true, currentWindow: true ), tabs => ( if (tabs) ( chrome.tabs.reload (tabs.id) ) chrome.runtime.reload ( ) )) )

Tab reload is called before runtime.reload , otherwise it won't work - calling runtime.reload stops the script from executing. But since tab reloading works asynchronously, in the end everything is reloaded in the correct order - although it looks illogical in the code.


Well, the final touch is to launch a watchdog aimed at the folder with the extension code. But we do this only if the extension is loaded in developer mode, via "Load unpacked extension":


chrome.management.getSelf(self => ( if (self.installType === "development") ( chrome.runtime.getPackageDirectoryEntry(dir => watchChanges(dir)) )))

Thus, we save the developer from having to bother with manually cutting out this watchdog from the production build.

Finally

That's basically it. It is completely unclear, however, how to test such things. It’s unlikely that any Selenium will help here, or what? Feedback is welcome.

Google Chrome reloads pages. How to get rid of this?

The problem, in principle, is stated in the topic. Google Browser Chrome started reloading pages automatically. For example, I’m reading some post on LiveJournal, and he rips me off and reloads the page, throwing me to the top of the page. What kind of tricks are these? Reading long texts has become inconvenient. How to get rid of this automatic page reload?


Vadim | 24 June 2016, 14:49
try turning off chrome://flags/#enable-offline-auto-reload

Farxad | April 14, 2016, 00:50
On the “History” tab in the Google browser, I have complete chaos: it updates itself every 29-30 seconds (I measured it on purpose!). It is impossible to calmly “search and find” something there. Throws upward.
There are rumors that these are “virus surprises” from obsessive free, arrogant self-downloads from the Internet with the signature “mail.ru” (which have long “occupied” my Firefox browser, introducing various artistic crap that slows down the processes; they spontaneously update this Firefox, despite because I closed all sorts of “autoload” from the Internet on my computer; “Google search” was kicked out of all “search” places in the Firefox browser).
And these unnerving “crackers” in the Google browser are most likely also the result of its competitive HOSTILITY towards Google.

Farxad | 15 March 2016, 20:28
This is most likely a virus that, like the “shortcut virus” from flash cards, can hide very well. The invention of yet another moral monster, a “prankster” who seeks vulgar solace in “child sabotage.”

Alek55sandr5 | 10 July 2015, 12:02
Try the recommendations first previous user. Surely this should help. And if not, then reset your browser settings. To do this, go to your browser settings, and then click on “Show advanced settings”. And at the very bottom of the settings window, click on the "Reset settings" button. If nothing helps you, then you need to reinstall the browser.