background.js的配置
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
switch (request.type) {
case 'fetchChromeXmlrpc':
(async () => {
const response = await fetch(request.apiUrl, request.fetchCORSParams);
const resText = await response.text()
// console.log("chrome.runtime.onMessage.addListener fetchChromeXmlrpc response:", resText)
sendResponse(resText);
})();
break;
case 'fetchChromeJson':
(async () => {
const response = await fetch(request.apiUrl, request.fetchCORSOptions);
const resJson = await response.json()
console.log("chrome.runtime.onMessage.addListener fetchChromeJson response:", resJson)
sendResponse(resJson);
})();
break;
// 你可以定义任意内容,使用sendResponse()来返回它
case 'test':
sendResponse({'msg': 'test'});
break;
}
return true; // keep the messaging channel open for sendResponse
});
...大约 2 分钟