--- title: 'playwright报错缺少libatk-1.0.so.0:异常处理.md' date: 2021-08-18 10:29:40 tags: exception --- ### 最近开发qq机器人插件时想通过playwright自动github的页面 #### 1. 安装go-playwright ```go go get github.com/mxschmitt/playwright-go ``` #### 2.安装chromium ```go playwright install chromium ``` ### 3.自动化操作浏览器 ```go func GetPWScreen(url string) ([]byte, error) { pw, err := playwright.Run() if err != nil { log.Errorf("could not start playwright: %v", err) return nil, err } browser, err := pw.Chromium.Launch() if err != nil { log.Errorf("could not launch browser: %v", err) return nil, err } page, err := browser.NewPage() defer func() { page.Close() pw.Stop() }() if err != nil { log.Errorf("could not create page: %v", err) return nil, err } if _, err = page.Goto(url); err != nil { log.Fatalf("could not goto: %v", err) } data, err := page.Screenshot(playwright.PageScreenshotOptions{ FullPage: playwright.Bool(true), }) return data, err } ``` #### 4.遇到问题 在windows上一切都能运行 在linux(ubuntu 20.4)上遇到问题提示 ```go could not send message: could not send message to server: Protocol error (Browser.getVersion): Browser closed. ==================== Browser output: ==================== /root/.cache/ms-playwright/chromium-857950/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwright_chromiumdev_profile-fc8kRc --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-startup-window pid=250754 [pid=250754][err] /root/.cache/ms-playwright/chromium-857950/chrome-linux/chrome: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory =========================== logs =========================== /root/.cache/ms-playwright/chromium-857950/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI,BlinkGenPropertyTrees,ImprovedCookieControls,SameSiteByDefaultCookies,LazyFrameLoading --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --user-data-dir=/tmp/playwright_chromiumdev_profile-fc8kRc --remote-debugging-pipe --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-startup-window pid=250754 [pid=250754][err] /root/.cache/ms-playwright/chromium-857950/chrome-linux/chrome: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory ============================================================ Note: use DEBUG=pw:api environment variable to capture Playwright logs. ``` 找到重要语句 ``` error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory ``` 通过查询google 解决办法为: ``` sudo apt install libcups2 libnss3-dev librust-atk-sys-dev libatk-bridge2.0-dev librust-gtk-sys-dev ``` 安装对应依赖即可解决