兼容chrome68+
parent
d0a4903892
commit
9f736cd5b6
17
README.md
17
README.md
|
@ -1,4 +1,19 @@
|
|||
### DNS 缓存清除
|
||||
## DNS 缓存清除
|
||||
> 一键清除chrome的DNS缓存, 并刷新当前选项卡。 web开发的利器。
|
||||
|
||||
|
||||
### 更新日志
|
||||
|
||||
#### 2018/07/29 - v0.3.0
|
||||
* 兼容chrome 68+
|
||||
* chrome 68+之后, 谷歌移除了原清除DNS的API方法, 所以只能通过打开`chrome://net-internals/#dns`页面, 进行js注入的方式来清除缓存。
|
||||
* 但是要注入`chrome://net-internals/#dns`页面, 需要额外的授权。
|
||||
|
||||
> 授权方法:
|
||||
>> 1. 打开 `chrome://flags/`
|
||||
>> 2. 找到 `chrome:// URLs`, 并将其设置为`Enabled`
|
||||
>> **快速导航地址: ** [授权设置地址](chrome://flags/#extensions-on-chrome-urls)
|
||||
|
||||
|
||||
#### 2018/07/07 - v0.2.0
|
||||
* 首版, 支持chrome 67-; 不需要额外设置任何内容, 即装即用。
|
|
@ -5,8 +5,40 @@
|
|||
* @version $Id$
|
||||
*/
|
||||
|
||||
chrome.browserAction.onClicked.addListener(function(tab) {
|
||||
chrome.benchmarking.clearHostResolverCache()
|
||||
chrome.benchmarking.closeConnections()
|
||||
chrome.tabs.executeScript(tab.id, { code: 'location.reload()' })
|
||||
chrome.browserAction.onClicked.addListener(function(ctab) {
|
||||
let cid = ctab.id
|
||||
let tid = null
|
||||
let code = `
|
||||
let script = document.createElement('script')
|
||||
script.textContent = \`
|
||||
chrome.send('clearHostResolverCache')
|
||||
chrome.send('flushSocketPools')
|
||||
\`
|
||||
document.body.appendChild(script)
|
||||
`
|
||||
let callback = function() {
|
||||
chrome.tabs.remove(tid)
|
||||
chrome.tabs.executeScript(cid, { code: 'location.reload()' })
|
||||
}
|
||||
|
||||
chrome.tabs.query({}, function(tabs) {
|
||||
let done = false
|
||||
for (let i = 0, tab; (tab = tabs[i++]); ) {
|
||||
if (/^chrome:\/\/net-internals/.test(tab.url)) {
|
||||
tid = tab.id
|
||||
chrome.tabs.executeScript(tab.id, { code }, callback)
|
||||
done = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if (!done) {
|
||||
chrome.tabs.create(
|
||||
{ url: 'chrome://net-internals/#dns', active: false },
|
||||
function(tab) {
|
||||
tid = tab.id
|
||||
chrome.tabs.executeScript(tab.id, { code }, callback)
|
||||
}
|
||||
)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
"name": "DNS Flush",
|
||||
"description": "一键清除chrome的DNS缓存, 并刷新当前选项卡。 web开发的利器。",
|
||||
"version": "0.2",
|
||||
"version": "0.3",
|
||||
"author": "yutent",
|
||||
"icons": {
|
||||
"64": "icon64.png",
|
||||
|
@ -18,6 +18,7 @@
|
|||
},
|
||||
"permissions": [
|
||||
"tabs",
|
||||
"chrome://net-internals/#dns",
|
||||
"*://*/*"
|
||||
],
|
||||
"homepage_url": "https://doui.cc"
|
||||
|
|
Loading…
Reference in New Issue