T
T
teodor7teodor72019-06-21 16:43:40
Google Chrome
teodor7teodor7, 2019-06-21 16:43:40

What is the correct way to wait for chrome.tabs.executeScript() to complete before starting another one in a chrome extension?

How to run the script correctly to parse one page and then move to another. Because, as a result of the execution of the asynchronous For method, it passes without waiting for the completion of chrome.tabs.executeScript (). It is necessary that the page counter increase after the completion of chrome.tabs.executeScript ()

getAccaunts: function(url, pages){
          for(page = 1; page <= pages; page++){

                      chrome.tabs.executeScript(null,{ code: `var data = []; var arr = document.getElementsByClassName('search-result--person');
                      for (let item of arr) {
                            data.push(item.getElementsByTagName('a')[0].href);
                          }
                        console.log(  data);
                        window.location.href = window.location.href + '&page=${page}';

                      `}, function(result){

                    //        console.log(result);
                          //      arrAccount = result.map(function (name,item,arr) {console.log(name,item,arr); return data.getElementsByTagName('a')[0].href})
                      });

                    //  chrome.tabs.executeScript(null,{ code: `console.log( 'url - ${url}?page=${page}')`});
    //        chrome.tabs.executeScript(null,{ code: `console.log(${arrAccount[0]})`});
          }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question