Upgrade to Pro — share decks privately, control downloads, hide ads and more …

impression of google chrome headless

impression of google chrome headless

teitei_tk

May 31, 2017
Tweet

More Decks by teitei_tk

Other Decks in Programming

Transcript

  1. ChromeHeadless
    modeΛ৮ͬͨॴײ
    2017/05/31 @teitei_tk

    View full-size slide

  2. ࣗݾ঺հ
    • @teitei_tk
    • ࠷ۙ͸ϋΠϥϧԦࠃΛฏ࿨ʹ͢ΔͨΊʹؤுͬ
    ͯ·͢ɻ

    View full-size slide

  3. Chrome Headless
    ͱ͸ʁ

    View full-size slide

  4. ͍ΘΏΔHeadlessϒϥ΢β
    • ޡղΛঝ஌Ͱݴ͑͹ɺGUIͷແ͍Chromeɻ
    • GUI͸ͳ͍͕ɺ಺෦తʹ͸ϖʔδͷϨϯμϦϯά
    ͔ΒJavaScriptͷ࣮ߦ౳ɺϒϥ΢βͬΆ͍͜ͱ͕
    Ͱ͖Δ

    View full-size slide

  5. Ͳ͏͍͏༻్͕͋Δͷ
    • WebApplicationͷςετ
    • ͍ΘΏΔE2E
    • WebPageͷΩϟϓνϟࡱӨ
    • WebαΠτͷεΫϨΠϐϯά
    • DDoS߈ܸ

    View full-size slide

  6. ͳͥ
    Chrome Headless͔

    View full-size slide

  7. PhantomJSͷࢮ๢

    View full-size slide

  8. PhantomJSͱ͸
    • Headlessϒϥ΢βͷҰͭ
    • ͓ͦΒ͘Ұ൪ਓؾ͕͋ΔͷͰ͸ͳ͍ͩΖ͏͔
    • ͔͠͠ɺ2017/05/30ݱࡏͰissue͸1848ɺPull
    Request͸58ͱ։ൃ͸ఀ଺͍ͯ͠Δ
    • https://github.com/ariya/phantomjs/

    View full-size slide

  9. PhantomJS is Dead
    • ͦͯ͠།Ұͷϝϯςφ͕ࠓޙ͸ΈͳChrome Headlessʹ
    ৐Γ׵͑ΔͩΖ͏ͱϝϯςφΛࣙ೚Λએݴɻ
    • https://groups.google.com/d/msg/phantomjs/9aI5d-
    LDuNE/5Z3SMZrqAQAJ
    • ࠓޙͷߏ૝͸͋Δͷ͔ɺphantomiumͱ͍͏PhantomJS +
    ChromeHeadlessͷ୯ޠ͕૊Έ߹Θͬͨ͞ϨϙδτϦ͸͋
    Δ
    • https://github.com/Vitallium/phantomium

    View full-size slide

  10. ͱ͍͏ͷ͕എܠ

    View full-size slide

  11. Կނ
    Chrome Headless͔

    View full-size slide

  12. • Google͕։ൃ͍ͯ͠Δͱ͍͏҆৺ײ
    • Webඪ४΁ͷ४ڌ͕ૣ͍ͷͰɺ͍ͪૣ͘ػೳ͕࢖͑Δɻ
    • ֤छAPIͷར༻͕Մೳ
    • ServiceWorker
    • IndexedDB
    • Memory Heap Profiler
    • etc

    View full-size slide

  13. ͱ͍͏Θ͚Ͱ
    ৮ͬͯΈͨ

    View full-size slide

  14. Setup
    • Chrome Ver59Ҏ͕߱ඞਢ
    • ݱࡏ(2017/05/30)ͷChromeͷStable Version͸58
    • Chrome CanaryΛ࢖͏ͱྑͦ͞͏

    View full-size slide

  15. ؆୯ͳ΋ͷͳΒ͙͢ग़དྷΔ
    • ShellͰ͙͢ग़དྷΔ
    • DOMͷग़ྗ
    • PDF࡞੒
    • Ωϟϓνϟͷऔಘ
    • eg. $ chrome --headless --disable-gpu --dump-
    dom https://www.chromestatus.com/

    View full-size slide

  16. ద౰ʹWrapperॻ͍ͨ
    • ΩϟϓνϟͷࡱӨ
    • https://wobfnz0lh2.execute-api.us-
    west-2.amazonaws.com/dev/chrome?url=https://
    google.co.jp
    • PDFͷੜ੒
    • https://wobfnz0lh2.execute-api.us-
    west-2.amazonaws.com/dev/pdf?url=https://
    google.com/

    View full-size slide

  17. • ݴޠɿNode.js
    • ओʹ࢖༻ͨ͠ϥΠϒϥϦ
    • chrome-remote-interface
    • ChromeͷAPIΛୟ͘Node.jsϥΠϒϥϦ
    • lighthouse
    • ChromeΛىಈ͢Δϔϧύʔ͕هࡌ͞Ε͍ͯΔ
    ϥΠϒϥϦ

    View full-size slide

  18. ॴײ
    • ҆ఆԽ·Ͱ͸΋͏গֻ͔͠Γͦ͏ɻ
    • Ṗͷ--disable-gpu Option
    • API͕·ͩམͪண͍͍ͯͳ͍ͷͰຊ൪౤ೖ͸·ͩආ͚ͨ΄͏
    ͕ྑͦ͞͏
    • ͱ͸͍͑PhantomJSͷޙ佂ʹ͸࠲Γͦ͏ɻ
    • ಈ޲͸௥͓͖ͬͯ·͢ɻ
    • Կ͔͋ͬͨΒهࣄͰ΋ॻ͍ͯڞ༗͠·͢ɻ

    View full-size slide