'chrome.tabs.executeScript not loading DOM properly

I am making a chrome extension so that when the extension plugin clicked, then it redirects a page, where it fetch the DOM of that page and search a particular name of that page. After searching that name in DOM , i change the extension icon according that. But i am facing issue of page loading . for getting the DOM Content of that page, i use below code:

chrome.tabs.onActivated.addListener((activeInfo) => {
    chrome.tabs.get(activeInfo.tabId, function (tab) {
  setTimeout(function () {
        chrome.tabs.executeScript(null, {
            file: "getPagesSource.js"
        }, function () {
            if (chrome.runtime.lastError) {
                console.log("error");
            }
        });
    }, 4000);
        
    });
});

Here i have given a time of 4 secs for page load. without time out function page loading takes time and it gives error. sometimes the page loading has been finished before that above time. and sonetimes it takes more than that time. So how do i overcome this page loading issue to reach my goal?



Solution 1:[1]

In case you're on shared hosting and have no access to the command line, you could establish the link to the public folder by using this route in your web.php:

Route::get('/linkstorage', function () { $targetFolder = base_path().'/storage/app/public'; $linkFolder = $_SERVER['DOCUMENT_ROOT'].'/storage'; symlink($targetFolder, $linkFolder); });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ouflak