take taburl from current tab
-
estatistics last edited by estatistics
I have downloaded a chrome extension for opera browser.
"https://github.com/zeyad-shaban/image-handling-shortcuts/issues"I like to modify it in order to display the url of current active tab in his "html info page" (popup.html) to use it later for other things.
in manifest.json (the permisions)
"permissions": [ "tabs", "activeTab" ]
in popup.html (in body somewhere)
<span id="url"></span> <script src="popup.js"></script>
popup.js (all of it)
function _getCurrentTab(callback){ //Take a callback var theTab; chrome.tabs.query({active:true, currentWindow:true},function(tab){ callback(tab); //call the callback with argument }); }; _displayTab(tab){ //define your callback function console.log(tab); }; _getCurrentTab(_displayTab); //invoke the function with the callback function reference async function getCurrentTabUrl () { const tabs = await opera.tabs.query({ active: true }) return tabs[0].url } getCurrentTabUrl (); async function getCurrentTaba() { let queryOptions = { active: true, lastFocusedWindow: true }; let [tab] = await opera.tabs.query(queryOptions); return tabs[0].url; } getCurrentTaba(); async function getTab() { let queryOptions = { active: true, currentWindow: true }; let tabs = await chrome.tabs.query(queryOptions); return tabs[0].url; } getTab(); chrome.tabs.onUpdated.addListener(function () { console.log("TAB UPDATED") getTab().then(url => { console.log(url); }) }) chrome.action.onClicked.addListener((tab) => { console.log(tab.url); }); chrome.action.onClicked.addListener(function(tab) { // No tabs or host permissions needed! console.log('Turning ' + tab.url + ' red!'); chrome.scripting.executeScript({ code: 'document.body.style.backgroundColor="red"' }); }); chrome.browserAction.onClicked.addListener(function() { chrome.tabs.create({ 'url': 'https://www.opera.com' }); });
all these code functions taken from various places in web dontwork. When i click on the icon of the extention, (popup.html) do not display current tab url.
I have tried similar different snipsets with no success. What is going wrong?
What i must change in order to display the url of current tab in its info html page?
-