I want to get current tab URL without tabs permission and just activeTab permission

185 views
Skip to first unread message

James Akpan

unread,
Jul 5, 2023, 5:10:30 PM7/5/23
to Chromium Extensions
Please how can I get the current active tab url when a user click on a button on my extension without using the tabs permission or webNavigation permission and not using host_permissions too. Thanks! 

Patrick Kettner

unread,
Jul 5, 2023, 5:46:12 PM7/5/23
to James Akpan, Chromium Extensions
What kind of button? Like the browser_action icon in the toolbar?

On Wed, Jul 5, 2023 at 5:10 PM James Akpan <ja...@mosaiqlabs.com> wrote:
Please how can I get the current active tab url when a user click on a button on my extension without using the tabs permission or webNavigation permission and not using host_permissions too. Thanks! 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/f30596be-7f1b-4486-8818-d23d361da92bn%40chromium.org.

Simeon Vincent

unread,
Jul 5, 2023, 7:07:16 PM7/5/23
to Patrick Kettner, James Akpan, Chromium Extensions
Sounds like you want the activeTab permission. Once you declare it in your extension's manifest, you can access a tab's URL when the user invokes your extensions. For example:

chrome.action.onClicked.addListener((tab) => {
console.log(tab.url);
})

Simeon - @dotproto


James Akpan

unread,
Jul 5, 2023, 7:58:47 PM7/5/23
to Chromium Extensions, Simeon Vincent, James Akpan, Chromium Extensions, Patrick Kettner
Thanks sooo much for replying. But I have an error still. Or more like NOTHING happens. 
This is what my function looks like; 
const startSavingNewArticle = () => {
console.log("getting here")
chrome.action.onClicked.addListener((tab) => {
console.log(tab.url);
});
What do you think could cause the console not to run? 
I have the permissions set. I am calling this in a func not my background.

wOxxOm

unread,
Jul 6, 2023, 1:41:54 AM7/6/23
to Chromium Extensions, James Akpan, Simeon Vincent, Chromium Extensions, Patrick Kettner
chrome.action.onClicked makes sense in the background script (MV3 service worker), assuming of course you actually call the containing function and do it in the first turn of the event loop. If this code is in the popup then it won't do anything and is not necessary. Note that the popup is a separate window so it has its own separate devtools and console: right-click inside the popup and select "inspect" in the menu.
Reply all
Reply to author
Forward
0 new messages