나는 프로젝트에서 작업을 생산하는 크롬 확장입니다. 을 배경에서 페이지가 함수 이름 checkingProcess
. 이 함수가 실행될 때 새 탭을 열거나 탭이 업데이트됩니다. (나를 잡으려고 변화의 URL 은 여기에.)
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ı')
})
}, [])
그러나 내가 깨닫게 이 메시지는 프로세스가 단 한 번 실행되지만,나는 그것을 실행하는 데 필요 여러 번 데이터에 액세스하에서 배경이 동시에. 렇게 하려면 어떻게 해야 합니까?