提问人:blueseal 提问时间:10/27/2023 最后编辑:blueseal 更新时间:10/27/2023 访问量:33
如何安全地将消息(jwt令牌)从网站发送到扩展的内容脚本/背景?
How to securely send message (jwt token) from Website to extension's content script/background?
问:
我想安全地将消息(jwt 令牌)从我的网站发送到我的扩展的内容脚本/背景,但它似乎不可用(即 抛出错误)。(不是扩展的上下文)。chrome.runtime
chrome.runtime.sendMessage
website
// Send a message to the extension
chrome.runtime.sendMessage(
extensionId,
{ action: 'auth-token', data: token },
(response) => {
if (response.success) {
// Authentication succeeded
console.log('done');
} else {
// Authentication failed
console.log('failed');
}
}
);
extension background
chrome.runtime.onMessageExternal.addListener(
(message, sender, sendResponse) => {
console.log('========> ', { message, sender });
}
);
extension manifest v3
"externally_connectable": {
"matches": ["*://my-website.com/*"]
},
如何实现这一点,有什么想法吗?
答: 暂无答案
评论
chrome.runtime
www.
matches