How to auto click a button on page load using a chrome extension

My extension entails an auto-bidding bot that automatically applies orders for me on a freelance website. The extension selects an order and after the order page loads it is supposed to click the take order button but that’s where it shuts off. Here is my manifest file:

{
  "manifest_version": 3,
  "name": "Writerslabs Auto Order",
  "version": "1.0",
  "description": "Auto Order on Writerslabs.com",
  "action": {
    "default_popup": "popup.html"
  }, 
  "host_permissions": ["https://writerslabs.com/*"],
  "content_scripts": [
    {
      "matches": ["https://writerslabs.com/*"],
      "js": ["content.js"]
    }
  ],
  "background": {
    "service_worker": "background.js"
  },
   "permissions": [
    "tabs",
    "activeTab",
    "storage",
    "scripting"
  ]
}

And this is my service worker:

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
    if (request.func === "navigateToOrders") {
      chrome.tabs.sendMessage(request.tabId, { func: "navigateToOrders" });
    }
  });

  
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
    if (changeInfo.status === 'complete') {
        chrome.tabs.sendMessage(tabId, { action: 'runSelectEachOrder' });
    }
});



This is my content script that is supposed to click the button. Where am I going wrong?

chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
  if (request.func === "navigateToOrders") {
    window.location.href = "https://writerslabs.com/orders?page=1&all=1";
  }
});


chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
  if (message.action === 'runSelectEachOrder') {
      selectEachOrder();
  }
});

chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
  if (message.action === 'pressTakeorderbtn') {
    tkeOrderButton()
  }
});


// Function to take orders
function selectEachOrder() {
  // Select all rows
  const tableOrders = document.querySelectorAll("body > div.wrapper > div > section > div:nth-child(7) > table > tbody > tr");

  if (tableOrders.length > 0) {
    // Check if the first row indicates no orders were found
    const firstRowContent = tableOrders[0].textContent.trim();
    if (firstRowContent !== "No any orders were found.") {
      // Start processing orders
      processOrder(tableOrders, 0);
    } else {
      alert("There are no available orders!");
    }
  } 
  
// Recursive function to process each order
function processOrder(orders, index) {
  // Check if all orders are processed
  if (index >= orders.length) {
    return;
  }

  // Get the order ID
  const orderID = document.querySelector("td.first > div > a");

  if (orderID && orderID.textContent.trim() !== "No any orders were found.") {
    alert("Order ID: " + orderID.textContent);
    
    // Code to take the orders
    orderID.click();

    chrome.scripting.executeScript({
      target: { tabId: tab.id },
      function: takeOrderButtonScript
    });
    function takeOrderButtonScript() {
      // Use a setTimeout to ensure that the content is loaded before trying to interact with it
      setTimeout(function() {
        const takeOrderButton = document.querySelector(".modal-btn.green");
    
        if (takeOrderButton) {
          takeOrderButton.click();
        } else {
          console.error("Take Order button not found on the page.");
        }
      }, 2000); // Adjust the timeout as needed
    }
   
  } else {
    alert("There are no available orders");
    // Process the next order
    processOrder(orders, index + 1);
  }
}

}