0

I am trying to deploy a FastAPI application with Selenium WebDriver on Vercel. The application works fine locally, but when deployed to Vercel, I encounter a read-only file system error related to the Selenium WebDriver cache folder.

Error Message:

WARNING:selenium.webdriver.common.selenium_manager:Cache folder (/home/sbx_user1051/.cache/selenium) cannot be created: Read-only file system (os error 30)
127.0.0.1 - - [12/Feb/2025 21:42:10] "GET /api/search?q=laptop HTTP/1.1" 500 -

Code Snippets:

from selenium import webdriver
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.edge.options import Options as EdgeOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException, WebDriverException, NoSuchElementException
from bs4 import BeautifulSoup
from time import sleep
import urllib.parse
import re
import os


class StoreScraper:
    def __init__(self, store_name):
        self.store_name = store_name
        self.driver = self.setup_driver()

    def setup_driver(self):
        options = EdgeOptions()

        # Headless mode for performance
        options.add_argument("--headless")
        options.add_argument("--disable-gpu")
        options.add_argument("--no-sandbox")
        options.add_argument("--disable-dev-shm-usage")
        options.add_argument("--disable-extensions")
        options.add_argument("--disable-infobars")
        options.add_argument("--disable-browser-side-navigation")
        options.add_argument("--disable-blink-features=AutomationControlled")
        options.add_argument("--disable-popup-blocking")

        # Use a custom user-agent to avoid detection
        options.add_argument(
            "user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edg/109.0.0.0 Safari/537.36"
        )

        # Use the /tmp directory for WebDriver cache and user data
        temp_dir = "/tmp/webdriver"
        os.makedirs(temp_dir, exist_ok=True)
        options.add_argument(f"--user-data-dir={temp_dir}")
        options.add_argument(f"--disk-cache-dir={temp_dir}")

        # Initialize Edge WebDriver (Ensure `msedgedriver` is in PATH)
        service = EdgeService()
        driver = webdriver.Edge(service=service, options=options)
        return driver

    def quit_driver(self):
        if self.driver:
            self.driver.quit()
            self.driver = None

    # Other methods...

What I've Tried:

  • Using a temporary directory for the WebDriver cache.
  • Setting the cache directory to a temporary directory.

How can I resolve the read-only file system error related to the Selenium WebDriver cache folder when deploying my FastAPI application on Vercel?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.