import { commonFetch } from '@/http/fetch' // 每4分钟调用一次,保持background一直有效 export function PingPong() { chrome.tabs.query({}, (tabs = []) => { if (tabs.length) { let tab = tabs.filter((item) => { return item.active == true }) if (tab.length) { chrome.tabs.sendMessage(tab[0].id, { actionType: 'BACK_PING' }, () => { }); } } }) } export function httpNetWork(funcName, data, sender, sendResponse) { return commonFetch(data) .then((response) => { chrome.tabs.sendMessage(sender.tab.id, { actionType: 'BACK_HTTP_RESPONSE', data: response, funcName }); }) .catch(() => { chrome.tabs.sendMessage(sender.tab.id, { actionType: 'BACK_HTTP_RESPONSE', data: null, funcName }); }) } // 向content 发送消息 export const setContentMessage = (obj) => { chrome.tabs.query({}, (tabs = []) => { if (tabs.length) { let tab = tabs.filter((item) => { return item.active == true }) || [] if (tab.length) { // 未读消息 chrome.tabs.sendMessage(tab[0].id, obj); } } }) }