В моем расширении Chrome я хочу отправить сообщение от content.js
до background.js
.Вот что я делаю.
content.js
var currentURL = new URL(location.href)
console.log(currentURL) // URL {href: "https://developer.chrome.com/extensions/extension#type-ViewType", origin: "https://developer.chrome.com", protocol: "https:", username: "", password: "", …}
chrome.runtime.sendMessage({msg: 'urlUpdate', url: currentURL})
background.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
if(request.msg == 'urlUpdate'){
console.log(request.url) // {}
}
})
Почему я получаю пустой объект в background.js
?Как правильно получить request.url
?