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 插件开发
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
edokeh
April 23, 2012
Programming
820
7
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
chrome 插件开发
edokeh
April 23, 2012
More Decks by edokeh
See All by edokeh
Backbone 开发实战
edokeh
0
270
新一站 HTML5 触屏版开发总结
edokeh
34
8.6k
模块化的Javascript开发-FTF
edokeh
16
1.3k
iphone webapp入门实战
edokeh
14
900
REST实践指南
edokeh
12
720
Other Decks in Programming
See All in Programming
SODA - FACT BOOK(EN)
sodainc
1
220
LLM 101
dalinaum
0
470
Claude Code ハーネスDeep Dive – 君はどこまで制御する? -
takateeen_knj
6
4.4k
[JA] Domain Modeling with Vanilla Rails: 「操作」から再考するRailsの設計論
yasaichi
4
1.8k
Optunaを作ったときにやりたかったこと、その後 (2026/10/16, Optuna Meetup #3)
iwiwi
4
1.5k
そのデザイントークン、Flutterでも同じ見た目になりますか?
nakamizu
0
320
地方こそサーバーレス — 10年続けた、顔が見えるチームで確かな基盤を / Serverless Matters Most in Regional Areas — 10 Years of Building Reliable Foundations with Close-Knit Teams
seike460
PRO
1
330
自作Discord音声botをLambda MicroVMsに移行した話 / Migrating My Discord Voice Bot to Lambda MicroVMs
akihisaikeda
1
300
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.8k
當我們開始不讀 Code - AI Agent 時代,Code Review 與 Clean Code 還剩下什麼?
jame2408
1
370
느린 네트워크와 저사양 디바이스 사용자를 위한 웹뷰 로딩 시간 개선기
kmkim
1
220
AI Augmentation Techniques with Liberty
ivargrimstad
1
420
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.7k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
510
Designing for Timeless Needs
cassininazir
1
550
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
580
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
GraphQLの誤解/rethinking-graphql
sonatard
75
12k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
Typedesign – Prime Four
hannesfritz
42
3.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1.1k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.9k
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.3k
sira's awesome portfolio website redesign presentation
elsirapls
0
500
Transcript
Chrome Extension开发入门 葛亮@焦点科技 2012.4.23
简介 • 扩充Chrome功能 – 增强Chrome界面 – 修改页面 • 使用HTML/Javascript/CSS编写 –
可以使用HTML5/ES5/CSS3 • Chrome提供辅助API • 自动更新
My Chrome Extensions
插件架构 popup popup page background page page action browser action
content scripts web page Chrome Extension API
文件结构 .crx 压缩文件夹 manifest.json 配置文件 *.html *.js *.css *.png *.jpg
*.gif 其他文件
manifest.json { // 必需 "name" : "my extension", "version" :
"0.1", "manifest_version" : 2, // 推荐 "description" : "It’s nice", "icons": { "16" : "icon16.png", "48" : "icon48.png", "128" : "icon128.png“ } }
Startup • 新建空文件夹 • 新建并编写manifest.json • 通过Chrome“载入正在开发的扩展程序”
例子1:员工查询 • 架构 popup popup page web page OA服务器 Ajax交互
例子1:员工查询 1. 准备工作 抓http包
例子1:员工查询 2. 添加带popup页面的按钮 使用browser action 在工具栏添加按钮 manifest.json { … …
"browser_action" : { "default_icon" : "icon.png", "default_title" : "焦点员工通讯录", "default_popup" : "popup.html" } }
例子1:员工查询 3. 使用跨域ajax 添加权限 书写代码 manifest.json { … … "permissions"
: [ "http://oa.vemic.com/*" ] }
例子2:BBS通知 • 架构 popup popup page background page web page
服务器 Ajax交互 修改badge 浏览器的 WebDB
例子2:BBS通知 1. 编写服务器端 2. 添加带popup页面的按钮
例子2:BBS通知 3. 添加background页面 – 长生命周期的js – 所有Chrome进程共享一份 – 一般用于执行后台任务 manifest.json
{ … … "background" : { "scripts" : ["background.js"] } }
例子2:BBS通知 4. 修改badge – 图标上的数字徽章 – 使用Chrome Extension API •
chrome.browserAction.setBadgeText(); • chrome.browserAction.setBadgeBackgroundColor();
例子3:屏蔽选择提示 • 架构 content scripts web page 修改页面DOM
例子3:屏蔽选择提示 • 添加Content Scripts – 运行于特定页面上的脚本 – 不能使用Chrome Extension API
– 运行于“沙箱”中,不用担心全局变量污染 manifest.json { … … "content_scripts" : [ { "matches" : ["http://baidu.com/*"], "js" : ["sth.js"], "css" : ["sth.css"] } ] }
例子3:屏蔽选择提示 • 代码实现 – 针对网易新闻 var ne = document.getElementById("btn_wrapper"); ne.parentNode.removeChild(ne);
– 针对新浪微博 #selectionShare img{ display: none; } – 配置文件
debug • background • popup • content scripts
打包发布
自动更新 manifest.json { … … "update_url" : "http://myhost.com/ext/updates.xml" }
编写技巧 • 代码只需兼容Chrome即可 所以… 让浏览器兼容性玩儿蛋去吧!
编写技巧 • 使用HTML5/CSS3/ECMAScript5 – 使用ES5 – 使用HTML5 • 参见例子2 HTML5
WebDB • 抛弃jQuery document.querySelectorAll(selector) – 使用CSS3
Q&A