I created a Telegram bot using aiogram. The bot should follow the link, take a screenshot of the page and send it to the user. But when the bot tries to start Chrome using Selenium, Chromedriver gives an error:
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.42.591071 (0b695ff80972cc1a65a5cd643186d2ae582cd4ac),platform=Linux 5.8.0-1041-aws x86_64)
Here is the part of the code that is responsible for working with the browser:
async def send_screen(chat_id, url):
import os
from selenium import webdriver
from loader import bot
# Chrome launch
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(executable_path=r'/usr/local/bin/chromedriver', options=options)
# sending screenshot
driver.get(url)
photo_path = f'img/{str(chat_id)}.png'
driver.save_screenshot(photo_path)
await bot.send_photo(chat_id, photo=open(photo_path, 'rb'))
os.remove(photo_path)
driver.quit()
Everything worked fine before. I don’t understand what the problem is?