Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Chrome拡張を使ったDOM構造の取得
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
mr.terada
May 26, 2022
Programming
850
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Chrome拡張を使ったDOM構造の取得
mr.terada
May 26, 2022
Transcript
21 slides
Chrome拡張を使った DOM構造の取得
自己紹介 • 受託系の企業→SESで金融系システムの開発したりアプリ開 発したり→いまここ • ほぼほぼPHP、Javascriptは入社前はjQueryメイン • 入社後CloudCircus社「Fullstar」のSM、リードエンジニア 寺田 真理
お話しする概要 • Fullstarの概要・同時に開発したChrome拡張[Fullstar guide editor] のご紹介 • Chrome拡張の「よく見るサンプル以上」に挑戦したい方へ Chrome拡張のざっくり入門編 •
初めて拡張機能開発+プロダクトとして活用して
Fullstarとは?
Saasをターゲットとした カスタマーサポート支援システム 例えば 契約直後のある程度固定した問い合わせ対応に人手が取られ る 例えば 登録までは終わってるけどログイン後ちゃんと使ってくれて ない
チュートリアル機能(プロダクトツアー)で解消
お客様のサイト <div>動画</div> <div>画像</div> <div>吹き出し</div> <iframe></iframe>
new Promise(...) DBからCSSセレクターの取得 CSSセレクターからの相対位置でガイド要素を表示 設定されているURLか? ⇨ NO ⇨中断 「次」のガイドへ進む Iframe
どこでChrome拡張を使うの?
• チュートリアルを表示したい要素をお客様のサイトから取得す る必要がある • エンジニア不要で作成できるサービスであるため、 HTMLやJavascriptの知識がなくても設定が簡単に可能にした い!
Chrome拡張によってお客様サイト上のコードを取得
Chrome拡張によってお客様サイト上のコードを取得 お客様のサイト スクリプト(content_scriptなど) Chrome拡張 [ Fullstar guide editor ] 拡張機能側の画面⇨スクリプト⇨お客様のサイト(アクティブタブ)へのアク
セスは下記に上げるようなインターフェースを利用します。 • MessageChannel • chrome.tab.sendMessage • chrome.scripting.executeScript
Chrome拡張によってお客様サイト上のコードを取得 お客様のサイト スクリプト(content_scriptなど) Chrome拡張 [ Fullstar guide editor ] ①マウスポインタの
X軸・Y軸を取得 ②取得した座標から一致する 要素の取得 ※document.elementFromPoint(X, Y) ③一致した要素から セレクターの文字を 生成
Fullstarの拡張機能の構成(一部抜粋) { "manifest_version": 3, "permissions": ["activeTab", "cookies", "tabs","scripting"], "background": {“service_worker”:
“xxxxxxxx”}, "web_accessible_resources": [{ "resources": ["拡張機能のIframe", "拡張機能内の操作.js",...] }], "action": { "default_popup": "popup.html", }, "author": "Cloud CIRCUS inc.", }
Fullstarの拡張機能の構成(一部抜粋) { "manifest_version": 3, "permissions": ["activeTab", "cookies", "tabs","scripting"], "background": {“service_worker”:
“xxxxxxxx”}, "web_accessible_resources": [{ "resources": ["拡張機能のIframe", "拡張機能内の操作.js",...] }], "action": { "default_popup": "popup.html", }, "author": "Cloud CIRCUS inc.", } バックグラウンドで動く スクリプト Chrome拡張機能で 利用する権限をリストアップ 拡張機能内で利用する ライブラリやJS、Iframeなどを列挙する ※ ここではワイルドカード指定もOK いまから作る拡張機能はmanifest_versionは3 じゃないと審査は通りません
• activeTab/tabs アクティブタブの情報や、タブに対してスクリプトを実行するた めに必要な権限 • cookies cookieを利用する場合に必要 例:chrome.cookies.getAll… • scripting
v3以降のみ利用可能。Webページに対してスクリプトを送信でき る。例:chrome.scripting.executeScript … Fullstarの拡張機能の構成(一部抜粋)
Popup.html contents_script ブラウザ Cookie tab Storage Alerms 適切な権限を設定した上で、 スクリプトを実行したい時は chrome.scripting.executeScript また、 ブラウザに対してデータを送信したい時などは chrome.tabs.sendMessageを利用します。
良い点 • 開発の導入まで早い!公開も安い! Chromeさえあればよい • 日々の業務効率化など「自分だけの ツール」が簡単につくれる • JSなので勉強しやすい •
iOSのアプリ審査と比べると審査は早 め。V3だと即審査OKでした 初めて拡張機能開発+プロダクトとして活用して 引っかかりやすい部分 • 書籍が少なすぎる • ちょっと踏み込もうと思うと情報が 少ない分止まりがち • 前回まで何の問題もなかったところ で審査が落ちたりすることが極稀に ある • Chrome拡張の管理画面だけではDL 数などの評価が足りないかも?
まとめ
DOM操作ができることでWebプログラマの ちょっとした効率化にも! 拡張機能のDL制限やセキュリティ上の不安など ある方にはローカル開発さらにおすすめです 「空き時間で」開発できるChrome拡張 「思ったよりいいのできたな」って時はぜひ Chromeウェブストアへ🎈
ありがとうございました
Other Decks in Programming
See All in Programming
Next.js: The final boss of Web Performance
guaca
0
400
AWS CDKを理解するために公式の定義を深掘って解説してみる / Understanding AWS CDK by Digging into Its Official Definition
akihisaikeda
3
300
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
180
学びを記事・スライド・Xへ高速展開する― AI-assisted Learning Loopで回すコンテンツ生成術
ochtum
0
210
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
290
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
230
作れるエンジニアから、価値を届けるエンジニアへ
ryunakayama
1
280
AI時代のIaC入門 〜なぜインフラをコードで管理したいのか?〜 / Introduction to IaC in the AI Era
akihisaikeda
6
1.5k
はじめてのPLATEAU
nokonoko1203
1
650
Engineering Biometric UX Across Android Versions | DroidKnights 2026
ryunen344
1
200
Secure Your Coding Agent Like It’s Malware (v1.5) 🇬🇧 @Code.talks 2026
richargh
0
140
まずはコードより業務と向き合う:テーブル解体のためにPdMを呼んだ話
sakawe_ee
0
220
Featured
See All Featured
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.4k
Writing Fast Ruby
sferik
630
63k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
940
Git: the NoSQL Database
bkeepers
PRO
433
67k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.4k
Designing for Timeless Needs
cassininazir
1
560
The SEO Collaboration Effect
kristinabergwall1
1
620
The MySQL Ecosystem @ GitHub 2015
samlambert
251
13k
The Cult of Friendly URLs
andyhume
79
7.1k
Paper Plane (Part 1)
katiecoart
PRO
3
12k