feat: 新增包文件
This commit is contained in:
40
packages/electron-chrome-extensions/spec/fixtures/chrome-webNavigation/background.js
vendored
Normal file
40
packages/electron-chrome-extensions/spec/fixtures/chrome-webNavigation/background.js
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/* global chrome */
|
||||
|
||||
const eventNames = [
|
||||
'onBeforeNavigate',
|
||||
'onCommitted',
|
||||
'onCompleted',
|
||||
'onCreatedNavigationTarget',
|
||||
'onDOMContentLoaded',
|
||||
'onErrorOccurred',
|
||||
'onHistoryStateUpdated',
|
||||
'onReferenceFragmentUpdated',
|
||||
'onTabReplaced',
|
||||
]
|
||||
|
||||
let activeTabId
|
||||
|
||||
let eventLog = []
|
||||
const logEvent = (eventName) => {
|
||||
if (eventName) eventLog.push(eventName)
|
||||
if (typeof activeTabId === 'undefined') return
|
||||
|
||||
eventLog.forEach((eventName) => {
|
||||
chrome.tabs.sendMessage(activeTabId, { name: 'logEvent', args: eventName })
|
||||
})
|
||||
|
||||
eventLog = []
|
||||
}
|
||||
|
||||
eventNames.forEach((eventName) => {
|
||||
chrome.webNavigation[eventName].addListener(() => {
|
||||
logEvent(eventName)
|
||||
})
|
||||
})
|
||||
|
||||
chrome.tabs.query({ active: true, windowId: chrome.windows.WINDOW_ID_CURRENT }, ([tab]) => {
|
||||
activeTabId = tab.id
|
||||
logEvent()
|
||||
})
|
||||
|
||||
console.log('background-script-evaluated')
|
||||
Reference in New Issue
Block a user