mirror of https://github.com/jumpserver/jumpserver
Merge pull request #11306 from jumpserver/pr@dev@perf_chrome_ext
fix: 修复 chrome 插件不生效的问题pull/11307/head
commit
ed54cc8507
|
@ -6,24 +6,25 @@ const debug = console.log
|
|||
// 监听标签页的创建事件
|
||||
chrome.tabs.onCreated.addListener(function (tab) {
|
||||
// 获取当前窗口的所有标签页
|
||||
debug('New tab add, tabs : ', tabs)
|
||||
debug('New tab add, tabs : ', tabs.map(t => t.id))
|
||||
tabs.push(tab)
|
||||
});
|
||||
|
||||
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
||||
debug('Tab changed xx: ', tabId, changeInfo, tab)
|
||||
debug('Tab status changed: ', tabId, ' => ', changeInfo.status)
|
||||
if (changeInfo.status !== 'loading') {
|
||||
return
|
||||
}
|
||||
const tabFind = tabs.findIndex(t => t.id === tabId)
|
||||
if (tabFind === -1) {
|
||||
debug('Tab not found: ', tabId, tabs)
|
||||
return
|
||||
tabs.push(tab)
|
||||
} else {
|
||||
Object.assign(tabs[tabFind], tab)
|
||||
}
|
||||
Object.assign(tabs[tabFind], tab)
|
||||
|
||||
const blockUrls = ['chrome://newtab/']
|
||||
if (!tab.url || blockUrls.includes(tab.url) || tab.url.startsWith('chrome://')) {
|
||||
alert('安全模式,禁止打开新标签页')
|
||||
debug('Blocked url, destroy: ', tab.url)
|
||||
chrome.tabs.remove(tabId);
|
||||
return
|
||||
|
@ -52,3 +53,11 @@ chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
|
|||
chrome.tabs.remove(tabId);
|
||||
}
|
||||
})
|
||||
|
||||
chrome.tabs.onRemoved.addListener(function (tabId, removeInfo) {
|
||||
debug('Tab removed: ', tabId)
|
||||
const tabFind = tabs.findIndex(t => t.id === tabId)
|
||||
if (tabFind !== -1) {
|
||||
tabs.splice(tabFind, 1)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
"scripts": [
|
||||
"background.js"
|
||||
],
|
||||
"persistent": false
|
||||
"persistent": true
|
||||
},
|
||||
"content_scripts": [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue