我工作上的一个项目,该项目产生的铬扩展。 在一个背景网页我有个功能,名为 checkingProcess
. 这个函数时执行新的选项是打开还是一个选项进行更新。 (我试图抓住变化的网址在这里.)
chrome.tabs.onActivated.addListener((activeInfo) => {
checkingProcess(activeInfo.tabId)
})
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
checkingProcess(tab.id)
})
然后在 checkingProcess
功能,我有一些功能,用于数据处理和API话。 然后我试图收到的消息,来自弹出式窗口。 这一消息表示的弹出窗口被打开过。
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.msg === 'popup_opened') {
sendResponse({
matches_length: response['matches'].length,
hostname: host,
})
}
chrome.runtime.lastError
})
在这之后,它会发送一个响应的弹出窗口。 在出,我听到的消息和使用的反应的弹出窗口。
useEffect(() => {
chrome.runtime.sendMessage({ msg: 'popup_opened' }, (res) => {
setHostname(res['hostname'])
setMatchesLength(res['matches_length'])
console.log(res['hostname'], 'burası')
console.log(res['matches_length'], 'burası')
})
}, [])
然而,我意识到这个消息的过程只是执行一次,但我需要运行多次访问中的数据的背景同时进行。 我怎么可以那样做?