之前尝试使用Prometheus的webdriver_exporter 来监控网页白屏时间,但是一直有问题,于是就自己写了一个脚本来监控。
目前了解到的白屏时间 = responseStart - navigationStart
大致代码如下:
from selenium import webdriver
source = "https://www.baidu.com"
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=chrome_options,executable_path="/usr/local/bin/chromedriver")
driver.get(source)
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
blanktime = responseStart - navigationStart
print("Back End:%s" % blanktime)
driver.quit()
在使用的过程中,可能还会遇到一个
“selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist” 或者 “The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.”
这两个问题要看下 /opt/google/chrome/google-chrome 的末尾是不是:
exec -a "$0" "$HERE/chrome" "$@"
如果不是的话,请修改为这样的。 that's all
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。