Title: How to pass url from background.js to popup.js?
Tags: javascript;google-chrome;google-chrome-extension;runtime
Question: I can't find any working code since getSelected is depreciated. But can anyone help me with how to achieve this?
chrome.action.onClicked.addListener((tab: chrome.tabs.Tab) =&gt; {
const urlTab: string = tab.url as string;
console.log(urlTab)
chrome.tabs.onActivated.addListener((activeInfo: chrome.tabs.TabActiveInfo) =&gt; {
const tabId: number = activeInfo.tabId;
chrome.tabs.get(tabId, (tab: chrome.tabs.Tab) =&gt; {
const urlTab: string = tab.url as string;
console.log(urlTab)
If I have this in background.js, how can I pass the urlTab in popup.js?
Thank you for helping me.
Comment: Im using manifest v3 and `runtime.getBackgroundPage()` not available .

Comment: chrome.action.onClicked won't work if your popup is defined in default_popup. Simply query the tab in your popup script directly: [How to get the currently opened tab's URL in my page action popup?](https://stackoverflow.com/q/10413911)

Comment: You don't need it.



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 0, 'CommentCount': 3, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2021:00:10/21/21', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><google-chrome><google-chrome-extension><runtime>', 'Title': 'How to pass url from background.js to popup.js?', 'ViewCount': 24, 'id': 69658246, 'user_AboutMe': None, 'user_AccountId': 22494537.0, 'user_DisplayName': 'user16691768', 'user_Reputation': 93.0, 'user_Views': 13.0, 'user_id': 16691768.0}}