mirror of
https://github.com/zero-peak/ZeroOmega.git
synced 2025-02-02 02:58:13 -05:00
Improve web request error detection and set badge for updated tabs.
This commit is contained in:
parent
7d9ab303e3
commit
11749c28fc
@ -197,16 +197,18 @@ class ChromeOptions extends OmegaTarget.Options
|
|||||||
if enabled and not @_requestMonitor?
|
if enabled and not @_requestMonitor?
|
||||||
@_tabRequestInfoPorts = {}
|
@_tabRequestInfoPorts = {}
|
||||||
@_requestMonitor = new WebRequestMonitor()
|
@_requestMonitor = new WebRequestMonitor()
|
||||||
@_requestMonitor.watchTabs (tabId, info, req, event) =>
|
@_requestMonitor.watchTabs (tabId, info) =>
|
||||||
return unless @_monitorWebRequests
|
return unless @_monitorWebRequests
|
||||||
if info.errorCount > 0
|
if info.errorCount > 0
|
||||||
|
info.badgeSet = true
|
||||||
badge = {text: info.errorCount.toString(), color: '#f0ad4e'}
|
badge = {text: info.errorCount.toString(), color: '#f0ad4e'}
|
||||||
chrome.browserAction.setBadgeText(text: badge.text, tabId: tabId)
|
chrome.browserAction.setBadgeText(text: badge.text, tabId: tabId)
|
||||||
chrome.browserAction.setBadgeBackgroundColor(
|
chrome.browserAction.setBadgeBackgroundColor(
|
||||||
color: badge.color
|
color: badge.color
|
||||||
tabId: tabId
|
tabId: tabId
|
||||||
)
|
)
|
||||||
else
|
else if info.badgeSet
|
||||||
|
info.badgeSet = false
|
||||||
chrome.browserAction.setBadgeText(text: '', tabId: tabId)
|
chrome.browserAction.setBadgeText(text: '', tabId: tabId)
|
||||||
@_tabRequestInfoPorts[tabId]?.postMessage(
|
@_tabRequestInfoPorts[tabId]?.postMessage(
|
||||||
@_requestMonitor.summarizeErrors(info, OmegaPac.getBaseDomain))
|
@_requestMonitor.summarizeErrors(info, OmegaPac.getBaseDomain))
|
||||||
|
@ -83,6 +83,9 @@ module.exports = class WebRequestMonitor
|
|||||||
|
|
||||||
return if req.tabId < 0
|
return if req.tabId < 0
|
||||||
return if req.error.indexOf('BLOCKED') >= 0
|
return if req.error.indexOf('BLOCKED') >= 0
|
||||||
|
return if req.error.indexOf('net::ERR_FILE_') == 0
|
||||||
|
return if req.url.indexOf('file:') == 0
|
||||||
|
return if req.url.indexOf('chrome') == 0
|
||||||
return unless reqInfo
|
return unless reqInfo
|
||||||
if req.error == 'net::ERR_ABORTED'
|
if req.error == 'net::ERR_ABORTED'
|
||||||
if reqInfo.timeoutCalled and not reqInfo.noTimeout
|
if reqInfo.timeoutCalled and not reqInfo.noTimeout
|
||||||
@ -121,6 +124,11 @@ module.exports = class WebRequestMonitor
|
|||||||
chrome.tabs.onReplaced?.addListener (added, removed) =>
|
chrome.tabs.onReplaced?.addListener (added, removed) =>
|
||||||
@tabInfo[added] ?= @_newTabInfo()
|
@tabInfo[added] ?= @_newTabInfo()
|
||||||
delete @tabInfo[removed]
|
delete @tabInfo[removed]
|
||||||
|
chrome.tabs.onUpdated.addListener (tab) =>
|
||||||
|
info = @tabInfo[tab.id] ?= @_newTabInfo()
|
||||||
|
return unless info
|
||||||
|
for callback in @_tabCallbacks
|
||||||
|
callback(tab.id, info, null, 'updated')
|
||||||
chrome.tabs.query {}, (tabs) =>
|
chrome.tabs.query {}, (tabs) =>
|
||||||
for tab in tabs
|
for tab in tabs
|
||||||
@tabInfo[tab.id] ?= @_newTabInfo()
|
@tabInfo[tab.id] ?= @_newTabInfo()
|
||||||
@ -139,7 +147,8 @@ module.exports = class WebRequestMonitor
|
|||||||
info = @tabInfo[req.tabId]
|
info = @tabInfo[req.tabId]
|
||||||
if info
|
if info
|
||||||
if status == 'start' and req.type == 'main_frame'
|
if status == 'start' and req.type == 'main_frame'
|
||||||
info = @tabInfo[req.tabId] = @_newTabInfo()
|
for own key, value of @_newTabInfo()
|
||||||
|
info[key] = value
|
||||||
info.requests[req.requestId] = req
|
info.requests[req.requestId] = req
|
||||||
if (oldStatus = info.requestStatus[req.requestId])
|
if (oldStatus = info.requestStatus[req.requestId])
|
||||||
info[@eventCategory[oldStatus] + 'Count']--
|
info[@eventCategory[oldStatus] + 'Count']--
|
||||||
|
Loading…
Reference in New Issue
Block a user