Modifying Chrome Logger - a post as an incentive to learn Google Chrome extensions and write your own

  • Tutorial
In my comment: habrahabr.ru/post/177709/#comment_6169843 I described the extension problem from the corresponding article, in addition to redirects there are also problems with the output of AJAX request logs and possibly in some cases with iframe headers.
I decided to find out why this happens and realized that my statement was too categorical. After webRequest ceased to be an experimental developer.chrome.com/extensions/experimental.webRequest.htmlNow you can write loggers "on the headers" that handle all previously problematic situations. I do not set as my goal to analyze all such situations, I just would like to show how the Chrome Logger extension can be modified to solve some of the above problems and it might be interesting for those who want to deal with the Google Chrome extensions with a simple example. Maybe someone after reading the post there will be a desire to write your extension.

The extension itself (current version 4.0.1) after installation is in most cases located in the
windows folder :
C: \ Users \ Username \ AppData \ Local \ Google \ Chrome \ User Data \ Default \ Extensions \ noaneddfkdjfnfdakjjmocngnfkfehhd \ 4.0.1_0
for linux:
/home/User name/.config/google-chrome/Default/Extensions/noaneddfkdjfnfdakjjmocngnfkfehhd/4.0.1_0
where noaneddfkdjfnfdakjjmocngnfkfehhd is the ID of this extension, see the figure below. This folder may be in another place, it all depends on the settings of your system, but I think you can now easily find it.



I recommend copying the folder 4.0.1_0 for further experiments to a place convenient for you on the disk, and delete the extension itself so that it does not “intersect” with the one being modified.
In the copied folder, we are interested in the chromelogger.js file,
namely the line:
chrome.webRequest.onResponseStarted.addListener (...
The onResponseStarted method is used in this linefor log output, but this method according to the webRequest documentation developer.chrome.com/extensions/webRequest.html works when:
Fires when the first byte of the response body is received.
those. after receiving the first byte of the response body, but since “redirecting” answers do not have a body, then their log is not displayed (as I wrote here: habrahabr.ru/post/177709/#comment_6169843 )
in order for the log to be displayed, the onResponseStarted method must be replaced with the onHeadersReceived method - now the line will look like:
chrome.webRequest.onHeadersReceived.addListener ( ...
after that we save the file, on the extensions page we turn on the “Developer Mode” checkbox and load our extension (folder 4.0.1_0) using the “Download unpacked extension” button. We activate it on the test page and try to log from the "redirecting" script - now the log is displayed!
This is a too simplified modification, perhaps in some situations the modified extension will not work correctly (for example, the onHeadersReceived method may work more than once), but I did not set out to write a “fully functional” patch — I just wanted to show how this can be done.

PS For logging into the Google Chrome console, there is also a good extension chrome.google.com/webstore/detail/php-console/nfhmhhlpfleoednkpnnnkolmclajemefworking on cookies, the author promised here habrahabr.ru/post/107810 to remake it on webRequest , but has not yet remade it. It perfectly logs redirects, ajax and iframes, but there are some problems with pop-up log notifications.
UPD: As it turned out from the comments, the author has already remade this extension and soon there will be a new version release!

Also popular now: