I have a browser extension rendering a react webpage in an iframe, and I want to be able to access the current page URL in the page rendered by the iframe.
My current solution is to send a message requesting the URL from background.js, but right now I am not able to send a message or get a response.
I would appreciate if you could help get the messenger working, or if you could let me know of a better way to get the current tab url.
This is the background.js
chrome.runtime.onMessageExternal.addListener((request, sender, sendResponse) => {
if (request) {
if (request.message) {
if (request.message === 'version') {
sendResponse({ version: '1.1.1.0' })
} else if (request.message === 'test') {
// this is where the url would be gotten
sendResponse("hello world")
}
}
}
return true
})
This is the file that sends the message
chrome.runtime.sendMessage('<<The local dev id of the extension>>', {message: "test"},
function(response) {
console.log(response);
}
);
The listener doesn't log anything to the console when I've included any the file that sends the message receive any response.