Problem with auto open tabs and do something and the close them with javascript

I have written a code which should work fine but i cant seem to find whats the problem, each part of the code works just fine individually, but not as a whole..
here is the code:

async function main() {
    // Get all div elements with the class "product-list" in products pages
    var cursorPointerDivs = document.getElementsByClassName('product-list');

    // Iterate through the div elements with the class "cursor-pointer"
    for (var i = 0; i < cursorPointerDivs.length; i++) {
        await new Promise((resolve) => {
            setTimeout(async function () {
                var currentDiv = cursorPointerDivs[i];
                // Check if the div has a child with class "block cursor-pointer"
                var aChild = currentDiv.querySelector('a.block.cursor-pointer');
                if (aChild && aChild.href != null) {
                    // Print the src attribute of the img child
                    console.log('Found source:', aChild.href);
                    await dothejob(aChild.href, 1, i + 1);
                }
                resolve(); // Resolve the promise after the timeout
            }, 2500);
        });
    }
}

async function dothejob(pUrl, pgindex, prindex) {
    return new Promise((resolve) => {
        var linkUrl = pUrl;

        // Open a new tab and navigate to the specified URL
        var newTab = window.open(linkUrl, '_blank');

        // Wait for a specified duration (e.g., 3000 milliseconds or 3 seconds)
        setTimeout(async () => {
            // Access the content of the new tab
            var newTabDocument = newTab.document;

            // Get all div elements with the class "cursor-pointer"
            var cursorPointerDivs = newTabDocument.getElementsByClassName('cursor-pointer');

            // Iterate through the div elements with the class "cursor-pointer"
            for (var ii = 0; ii < cursorPointerDivs.length; ii++) {
                var currentDiv = cursorPointerDivs[ii];
                // Check if the div has an img child with class "w-full inline-block"
                var imgChild = currentDiv.querySelector('img.w-full.inline-block');
                if (imgChild && !imgChild.closest('picture') && imgChild.src.includes('statics-public')) {
                    // Print the src attribute of the img child
                    console.log('Image source:', imgChild.src);

                    // Resolve the promise
                    resolve();
                    return; // Exit the loop after finding the first match
                }
            }

            // Close the new tab
            newTab.close();

            // Resolve the promise even if no match was found
            resolve();
        }, 3000); // Adjust the delay as needed
    });
}

// Call the main function
main();

the point is getting an image from each item from one page of items, open 10 at the same time and do the process, but this doesnt work or with a few teaks just does the first items and then stops while saying promise in console of the browser.

Im executing this code in the console windows of browser.

Thank you all.