Last active
July 20, 2024 18:58
-
-
Save sh4t/51a1face2056cbfa547a to your computer and use it in GitHub Desktop.
clearing chrome dns cache and sockets via js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# The MIT License (MIT) | |
# Copyright (c) 2015 Justin Shattuck <[email protected]>, F5 Networks, Inc. | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# The above copyright notice and this permission notice shall be included in | |
# all copies or substantial portions of the Software. | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
# THE SOFTWARE. | |
echo "" | |
echo "Dumping Google Chrome DNS Cache" | |
osascript <<EOD | |
tell application "Google Chrome" | |
tell front window | |
set origTab to active tab | |
set origTabIndex to active tab index | |
set theTab to make new tab with properties {URL:"chrome://net-internals/#dns"} | |
set isLoadDone to not loading of theTab | |
repeat until isLoadDone | |
set isLoadDone to not loading of theTab | |
end repeat | |
delay 1 | |
execute theTab javascript "g_browser.sendFlushSocketPools();g_browser.checkForUpdatedInfo(false);g_browser.sendClearHostResolverCache();" | |
close theTab | |
set active tab index to origTabIndex | |
-- uncomment the line below (remove -- ) if you would like previously opened tab to be reloaded. | |
-- reload origTab | |
end tell | |
end tell | |
EOD | |
echo "Finished dumping Google Chrome DNS Cache" |
when i use this i got
Uncaught ReferenceError: g_browser is not defined at <anonymous>:1:17
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
Someone asked if it was possible to dump/flush the local dns cache within the browser using Javascript. This is one way to do it, using bash to execute applescript, but it requires the user (a) be using an Apple and (b) they are using Google Chrome. I've adopted this to FireFox as well and will release, but for now this should work.
$ chmod +x /path/to/flush_chrome_dns.sh
$ /path/to/flush_chrome_dns.sh
Next steps, which are done, but I will create a repository that has this as an application that supports numerous browsers, has command line interface as well as a .app which could be used from Alfred workflow etc. Simple enough.