13
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

herokuでselenium利用時にクラッシュする場合の解決方法

Posted at

herokuでselenium利用時にクラッシュする場合の解決方法

はじめに

herokuでseleniumを利用する方へ向けた、クラッシュする場合の解決方法を記載しました。

発生事象

heroku上でseleniumを実行時に下記のようなエラーが発生しました。

Running python manage.py task on ⬢ xxxxx... up, run.9999 (Hobby)
Message: unknown error: session deleted because of page crash
from unknown error: cannot determine loading status
from tab crashed
  (Session info: headless chrome=81.0.4044.129)

解決方法

調べてみると、メモリ不足によるクラッシュのようです。
そのため、メモリ不足にならないように、seleniumを省メモリ化する対策をとればよさそうです。

1. seleniumの引数に省メモリ化するための引数をつける

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--remote-debugging-port=9222')
driver = webdriver.Chrome(settings.CHROME_PATH, options=options)

2. 画面サイズをできる限り小さくする

driver.set_window_size(950, 800)

参考

How do I prevent headless Chromium from crashing? - Heroku Help
https://help.heroku.com/DOB4Y0I4/how-do-i-prevent-headless-chromium-from-crashing

Rspecで突然謎のエラーが - Qiita
https://qiita.com/mishitoshi/items/3ca5a9a26ceb7e2cf034

Selenium::WebDriver::Error::NoSuchDriverError - Today I Learned
https://selleo.com/til/posts/mxkjoppuxm-seleniumwebdrivererrornosuchdrivererror

13
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?