找不到名称 'sendResponse'
Cannot find name 'sendResponse'
chrome.runtime.onMessage.addListener(
function(props) {
switch(props) {
case props.request_type = 'msg':
websocketClass.msgSubmit(props.data)
break;
case props.request_type = 'url':
websocketClass.msgSubmit(props.data)
break;
case props.request_type = 'his':
sendResponse({his: websocketClass.messages});
}
}
);
我有一个问题,尽管我添加了@types/chrome,sendResponse 仍然returns 上述错误。我怎样才能完成这项工作?
sendResponse
不是全局符号,它是侦听器的参数但您只指定了 props
,请参阅 documentation.
switch
永远不会匹配,它只会用值('msg'、'url'、'his')覆盖 request_type
。
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
switch (msg.request_type) {
case 'msg':
case 'url':
websocketClass.msgSubmit(msg.data);
break;
case 'his':
sendResponse({ his: websocketClass.messages });
case 'foo':
callFunctionThatReturnsPromise(msg).then(sendResponse);
// Keeps the internal channel open for sendResponse after this listener exits.
// Only use `return true` if you really invoke sendResponse asynchronously.
return true;
}
});
chrome.runtime.onMessage.addListener(
function(props) {
switch(props) {
case props.request_type = 'msg':
websocketClass.msgSubmit(props.data)
break;
case props.request_type = 'url':
websocketClass.msgSubmit(props.data)
break;
case props.request_type = 'his':
sendResponse({his: websocketClass.messages});
}
}
);
我有一个问题,尽管我添加了@types/chrome,sendResponse 仍然returns 上述错误。我怎样才能完成这项工作?
sendResponse
不是全局符号,它是侦听器的参数但您只指定了props
,请参阅 documentation.switch
永远不会匹配,它只会用值('msg'、'url'、'his')覆盖request_type
。
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
switch (msg.request_type) {
case 'msg':
case 'url':
websocketClass.msgSubmit(msg.data);
break;
case 'his':
sendResponse({ his: websocketClass.messages });
case 'foo':
callFunctionThatReturnsPromise(msg).then(sendResponse);
// Keeps the internal channel open for sendResponse after this listener exits.
// Only use `return true` if you really invoke sendResponse asynchronously.
return true;
}
});