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

BrowserExtension四方山話 #yapc8oji

BrowserExtension四方山話 #yapc8oji

#yapc8oji でトークしたブラウザ拡張に関するトークです。友だちになってください

pastak

July 02, 2016
Tweet

More Decks by pastak

Other Decks in Technology

Transcript

  1. OCR

  2. We are hiring!! • ݄ؒ1000ສUU 6600ສPV / month • JavaScript

    / Ruby on Rails / Golang • iOS / Mac / Windows App • Kyoto or Everywhere • Tokyo, Yokohama, Hokkaido • USA, Australia https://www.wantedly.com/companies/nota
  3. ϒϥ΢β֦ு͜Ε·Ͱ • Chrome, Opera • JS + CSS + HTML

    Ͱ࡞੒Մೳ • Firefox • XUL + XPCOMΛ༻͍ͨ։ൃ • Addon-SDKΛ༻͍ͨ։ൃ (crx / jpm) ͋͋ • Safari • JS + CSS + HTML Ͱ࡞੒Մೳ • ୠ͠ɺAPI͸Chromeͱେ͖͘ҟͳΔ
  4. ϒϥ΢β֦ு͜Ε͔Β • Chrome, Opera • JS + CSS + HTML

    Ͱ࡞੒Մೳ • Firefox • XUL + XPCOMΛ༻͍ͨ։ൃ ← ഇࢭ༧ఆ • Addon-SDKΛ༻͍ͨ։ൃ (crx / jpm) • Chromeޓ׵ͷWebExtension ← NEW!!!!!!!! • Safari • JS + CSS + HTML Ͱ࡞੒Մೳ • ୠ͠ɺAPI͸Chromeͱେ͖͘ҟͳΔ ※༏ઌॱҐ͸ ߴ͘ͳ͍ͦ͏ͳͷͰ ͙͢ʹഇࢭ͸ͳͦ͞͏
  5. ϒϥ΢β֦ு*͞Βʹ*͜Ε͔Β • Mozilla/MS/Operaͷ3ऀ͕֦ுػೳͷίΞAPIͷඪ४Խ ΛఏҊ • W3CͷBrowser Extension Community GroupͷϝʔϦ ϯάϦετʹ͓͍ͯɺϒϥ΢βͷ֦ுػೳʹ͓͚ΔίΞ

    API΍ϚχϑΣετɺύοέʔδΛඪ४Խ͢Δ͜ͱΛڞ ಉͰఏҊ • http://rockridge.hatenablog.com/entry/ 2016/05/05/110059 • https://github.com/browserext/browserext • https://twitter.com/browserext
  6. Coming to MS Edge ? • ݱࡏϓϨϏϡʔͰ͍͔ͭ͘ެ։͞ΕͯΔ • ϥΠϯφοϓΛݟͯΔͱɺChrome Extension

    ޓ׵ͬΆ͍Α͏ʹݟ͑Δ • WGʹ΋ࢀՃ͍ͯ͠Δ͖ͬ͠ͱͦ͏ͳΓͦ͏ • “in the future users will be able to download extensions from the Windows Store.” • https://developer.microsoft.com/en-us/ microsoft-edge/platform/faq/#extensions
  7. Chrome Extensionͱ͸ʁ • ։ൃ͸ JS / HTML / CSSͰߦ͏ •

    docs: https://developer.chrome.com/extensions • Background / content script / popup • ഑෍͸ Chrome Web Store • ແ৹ࠪ / ࠷ॳʹ$5ࢧ෷͏ ਤ͸ https://developer.chrome.com/extensions/overview ΑΓ
  8. Chrome / Opera • Opera͸Chromiumϕʔεͷϒϥ΢βͳͷͰجຊతʹ͸ͦͷ·· ಈ࡞͢Δ • https://dev.opera.com/extensions/ • Chrome

    Web Store͔ΒOperaʹΠϯετʔϧՄೳʹ͢Δ ExtensionͳΜͯ΋ͷ΋͋Δ • Sidebar΍Speed DialͳͲҰ෦OperaͷΈͰ࢖͑ΔAPI΋͋Δ • https://dev.opera.com/extensions/apis/
  9. Firefox Addonͷ͜Ε·Ͱ • XUL + XPCOMΛ༻͍ͨ։ൃ • Addon-SDKΛ༻͍ͨ։ൃ (crx /

    jpm) • ݩ “Jetpack” • JSͰखܰʹFirefox֦ுΛهड़Մೳʹ • ৄ͘͠͸ http://www.slideshare.net/pastak/ firefox-addon-sdk
  10. WebExtensionొ৔ • 2015೥8݄຤ ChromeExtensionޓ׵ͷWebExtension ܗࣜͷ֦ுΛαϙʔτ͢Δͱൃද • Firefox v46Ͱ Alpha Releaseʹ

    • 2016-08-02ͰStableʹͳΔ v48 Ͱ Stable Releaseͷ ༧ఆ • σεΫτοϓ޲͚ͷΈͳΒͣɺ Android൛΋ରԠର ৅ʂʂʂʂʂʂʂʂ • ͢ͰʹAMO͔ΒͷΠϯετʔϧͳͲ͸Մೳʹͳͬͯ ͍Δ
  11. ࠷৽ঢ়گ • ॾʑ΍ͬͯ͘ΕΔίϚϯυϥΠϯπʔϧ web-ext ొ ৔ • Build, Signɺauto run

    • https://blog.mozilla.org/addons/2016/04/29/ webextensions-in-firefox-48/ • Optionϖʔδαϙʔτ׬ྃ • chrome.*APIΛݺ΂ͳ͍όά͕͋Δʁ • ։ൃதΞυΦϯͷreload • TabMixPlusͳͲஶ໊ͳAddon༻ͷAPIΛ४උ͍ͯ͘͠
  12. ϋΠϒϦουΞυΦϯ • ௿ϨΠϠʔAPIͳͲΛར༻͍ͨ͠ΞυΦϯͳͲʹ޲͚ͯͷ ஈ֊తॲஔʢ࠶ىಈෆཁΞυΦϯͰ͋Δඞཁ͕͋Δʣ • Addon SDKͰ࡞ͬͨΞυΦϯ͔ΒWeb Extensionͷػೳ Λݺͼग़ͯ͠ར༻Ͱ͖Δ •

    chrome.runtime.sendMessageܦ༝Ͱ΍ΓͱΓ͢Δ • API͕શͯἧͬͨ࣌఺ͰwebextensionσΟϨΫτϦҎ֎ Λഁغ͢Δ͜ͱͰҠߦ׬ྃͱͰ͖Δ • ݱࡏઈࢍ࣮૷த https://bugzilla.mozilla.org/show_bug.cgi?id=1252215
  13. Ҡ২ͷ࣌ʹ֬ೝ͍ͨ͜͠ͱ • JS / CSS / HTML ͷͦΕͧΕ࣮૷ରԠঢ়گ • JSͷAPI΍CSSͷৼΔ෣͍͸ຊ౰ʹಉ͡ʁ

    • http://caniuse.com/ • chrome.*API ͷରԠঢ়گ • http://www.arewewebextensionsyet.com/ • APIͷҰཡ / ؔ࿈ bugzilla΁ͷࢀর / filterͱ͔͕ ͋ͬͯศར • https://developer.mozilla.org/en-US/Add-ons/ WebExtensions/Chrome_incompatibilities
  14. What’s wemf • ඞؚͣ·Ε͍ͯΔ΂͖ΩʔͱରԠ͢Δ஋Λ௥Ճ • ෆ଍͍ͯ͠ΔΩʔ͕͋Δ৔߹͸ package.json ͳͲ͔Βੜ੒ͭ͠ ͭɺର࿩ΠϯλʔϑΣΠεͰੜ੒͠·͢ •

    ະରԠͷΩʔΛ࡟আ • ݱঢ়ະରԠͷΩʔ͕͋ΔͱΠϯετʔϧʹࣦഊ͢ΔͷͰɺͦͷ Α͏ͳΩʔΛ࡟আ͠·͢ɻ • ະରԠͷΩʔϫʔυͷ࢖༻Λ௨஌ • web_accessible_resourcesͰϫΠϧυΧʔυ͕࢖͑ͳ͍ͳͲ͕ ͋ΔͷͰɺͦͷΑ͏ͳΩʔϫʔυΛؚΜͰ͍Δ৔߹͸࡟আͤͣ ʹ௨஌͠·͢ɻ
  15. Exports Chrome Extension 1. manifest.json ฤू͢Δ • wemf ࢖͏ͱγϡοͱग़དྷΔ͸ͣ 2.

    ඇޓ׵CSS / JS ରࡦ 3. Πϯετʔϧͯ͠ಈ͔ͯ͠ΈΔ 4. ڍಈͷո͍͠෦෼Λ try-catch ͢Δ • bugzilla ͱ͔ͱ͔ʹ৘ใͳ͍͔ݟΔ • NightlyͰࢼͯ͠ΈΔ • Ͳ͏͠Α͏΋ແͦ͞͏ͳΒbugzilla
  16. • src/firefox/manifest.json +78 • src/firefox/config.js +3 • src/firefox/_locales/ja/messages.json +8 •

    src/firefox/_locales/en_US/messages.json +8 • Rakefile +3 -1 • .gitignore +1 • ۭߦɾߦ຤εϖʔε੔ܗͳͲ +15 -22
  17. • src/firefox/manifest.json +78 • src/firefox/config.js +3 • src/firefox/_locales/ja/messages.json +8 •

    src/firefox/_locales/en_US/messages.json +8 • Rakefile +3 -1 • .gitignore +1 • ۭߦɾߦ຤εϖʔε੔ܗͳͲ +17 -24 ࣮࣭: +46 -17
  18. Case of Gyazo Extension • ͸ͯͳϒοΫϚʔΫChrome֦ுͷྫͱ΄΅ಉ͡ • Firefox ඇରԠͷCSSͳͲΛͳΜͱ͔͢Δ •

    JSͷৼΔ෣͍ͷࠩ෼Λٵऩ • AMOͷϨϏϡʔ௨աରࡦ • innerHTMLͰࡶʹྲྀ͠ࠐΜͰ͍ͨͱ͜ΖͳͲΛஸೡʹ ͢Δ • messaging APIͳͲͷόά͕࣏Δ v47 ͕ betaೖΓ͢Δ λΠϛϯάͰެ։ • ReleaseೖΓͨ͠λΠϛϯάͰgyazo.com͔Β༠ಋ https://github.com/gyazo/gyazo-browser-extension/pull/151/
  19. Case of Gyazo Extension • ࢖͑ͳ͍(ະ࣮૷) / όΪʔͳAPIΛճආ • Clipboard

    / Context Menu / Storage.sync etc • Clipboard͸·ͩ͜Ε͔Βʁ • Context Menu͸imageͷ਺͚ͩitemΛaddͯ͠͠ ·͏όά͕͕͋ͬͨv49Ͱमਖ਼ • Storage.sync΋͜Ε͔Β • Storage.localͳΒ࢖͑Δ • Firefox SyncͷΞΧ΢ϯτͱ૊Έ߹Θͤͯɺ΍ͬ ͍ͯ͘ʁ https://github.com/gyazo/gyazo-browser-extension/pull/151/
  20. Install Staging Build • Chrome Extension͸खݩͰSignՄೳ • Πϯετʔϧ͸Ұ౓ϩʔΧϧΛܦ༝͢Δඞཁ͕͋Δ • Web

    Extension͸AMOΛܦ༝ͯ͠Sign • SignAPIΛར༻͢Δͱ਺ेඵͰSign͞Εͯμ΢ϯϩʔυ༻URL ͕ൃߦ͞ΕΔ • ຊ൪༻ͱ͸ҧ͏idΛ෇͚͓ͯ͘ඞཁ͕͋Δ • Version΋ຖճ্͕Βͳ͍ͱ͍͚ͳ͍ • ͜ͷล͸Build࣌ʹྑ͍ײ͡ʹ • Version Λ YY.MM.DD.HHmm ͱ͔ʹ͢Δͱvalid׌ͭྑ ͍ײ͡ʹͳΔʁ
  21. ΤϥʔϝοηʔδϋϯυϦϯά • ChromeͩͱɺChrome Web Store΍GoogleͷϩάΠϯ ϖʔδͳͲʹcontent scriptΛinjection͠Α͏ͱ͢Δͱ ʰ~~cannot be scriptedʱͱ͍͏message͕ඈΜͰ͘Δ

    • Firefox͸࣮૷͕ҧ͍ͦ͏ͳͷͰɺྑ͍ײ͡ʹ͍ͯ͠ ͘ඞཁ͕͋Γͦ͏ • ͦͷΑ͏ͳϖʔδͰ͸ injectionग़དྷͳ͍ͷͰɺϘλϯ Λdisableʹ͢Δ
  22. chrome.tabs.captureCurrentTab • RetinaσΟεϓϨΠͳͲͷHigh DPI؀ڥରࡦ • GyazoExtensionͰ͸window.devicePixelRatioͳͲΛ ར༻ͯ͠αΠζΛॖখͨ͠Γ͍ͯ͠Δ • ChromeͱFirefoxͰ͸औಘͰ͖Δը૾ͷαΠζ͕ҟͳΔ •

    Chrome: ࣮ϐΫηϧ਺ͷΩϟϓνϟ • Firefox: දࣔϐΫηϧαΠζͷΩϟϓνϟ • Retinaͷ৔߹ɺFirefoxͰऔಘͰ͖ΔΩϟϓνϟͷ ը૾ͷԣ/ॎ෯͸Chromeͷ1/2ʹͳΔ
  23. ·ͱΊ • Chrome ExtensionͱFirefoxͷWeb Extension͸ͦΕͳ Γʹޓ׵͕͋Δ • ·ͩWebExtensionʹ͸ະ࣮૷ͩͬͨΓ଍Γͳ͍෦෼ ͕͋ΔͷͰɺͦͷ͋ͨΓ͸ͲΜͲΜࢦఠ͍ͯ͘͠ͱ ྑͦ͞͏

    • ϒϥ΢β֦ு͕͋Δ͔Βͦ͜ఏڙͰ͖Δମݧ͕͋Δ ͸ͣͳͷͰɺͦͷลΓ͕1ͭͷن֨ͷதͰఏڙͰ͖Δ ͷ͸ྑ͍͜ͱ • Edge͸ޙ௥͍ͦ͠͏ɻSafari͸Ͳ͏ͳΔʁʁ
  24. ৘ใऩूϦϯΫू • https://blog.mozilla.org/addons/ • Mozilla Addonϒϩάʹఆظతʹ৘ใࡌΔ • http://www.arewewebextensionsyet.com/ • ࣮૷ঢ়گ΍όάͳͲΛͬ͟ͱҰཡͰ͖Δ

    • https://developer.mozilla.org/en-US/Add-ons/WebExtensions • MDNͷ։ൃऀ޲͚υΩϡϝϯτ • https://bugzilla.mozilla.org/buglist.cgi? component=WebExtensions&product=Toolkit&bug_status=_ _open__&list_id=13093986 • WebExtensionؔ࿈ͷissueҰཡ