Home > Software design >  I'm trying to parse all the urls of the tabs I have open
I'm trying to parse all the urls of the tabs I have open

Time:01-28

I'm trying to copy the url's of all the open tabs with javascript and then put the urls into a html textarea, however it's not working. This is my code.

            chrome.windows.getCurrent({"populate":true}, function(currentWindow) {
               var tabURLs = [];
               var tabs = currentWindow.tabs;
               for (var i=0; i<tabs.length; i  ) {
                   tabURLs.push(tabs[i].url);
               }
               var textArea = document.getElementById("thing");
               var text = textArea.value;
               tabURLs.forEach(item => text  = item);
            });
        };

Keep in mind this is a google chrome extension, let me know how I can fix this!

CodePudding user response:

Your code is modifying a copy of the element's value, not the element itself.
You need to replace text = with textArea.value =

P.S. The code can be shortened:

chrome.tabs.query({}, tabs => {
  document.getElementById("thing").value = tabs.map(t => t.url).join('\n')l
});

CodePudding user response:

I don't think you are sending back the info you might be getting.

If you can debug it, check what the value of 'text' is at the end , but you aren't sending the data to anywhere that would show it.

  •  Tags:  
  • Related