Overview
Chrome extensions have pretty good documentation and pretty good community support. Naturally, you might expect that between docs and forums that you can get a small project up and running quickly.
Unfortunately, sometimes minor simple tasks can get lost in the weeds. Documentation usually only covers the basic, small, happy flow cases and forums usually only ask about difficult, large problems. Well what about issues of medium size and complexity? Leave that to the bloggers!
Here we’ll take a look at how to create a chrome extension that uses a Content Script to change the background color of any page using jQuery.
Manifest.json
First things first. You need a way to tell chrome what your intentions are, what components come with your extension, and when they apply. To do this, we’ll use a manifest file.
The manifest file contains some JSON formatted data that Google knows how to read. There is a lot of boiler plate info that you can explore, but, for our purposes, we want to pay special attention to the content script section:
{
"manifest_version": 2,
"name": "Page Changer",
"version": "0.1",
"description": "Page Changer",
"icons": { "16": "Icons/Logo16.png",
"32": "Icons/Logo32.png",
"48": "Icons/Logo48.png",
"128": "Icons/Logo128.png" },
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["jquery.min.js", "script.js"]
}
]
}
The content script must specify two things:
- The pages against which to run the code
- The external code files to run.
In this case, we’ve specified that we want to our content to run whenever the web url matches the pattern *://*/*
, which is to say for all protocols, for all domains, for all pages (in other words, run everywhere).
If you just wanted to target google.com or any of it’s content pages, then you could put that there.
The second thing we’ve specified is which files to run and in which order. First we’ll load jQuery from a local copy that we deploy, and next we’ll run a file called script.js
that we’ll look at in a second.
Script.js
In this simplified example, let’s say we just want to change the background color of the current page for a very obvious example of whether or not all the right components have been called. In a real world example, you might want to find all the links in the page and turn them a particular color. Or attach some code to any images on the page to allow you to easily email them. Whatever you want!
For now, let’s just run the following script which will find the body
element and use the css()
method in jQuery to apply the value blue
to the background
property:
$(function() {
$("body").css("background","blue");
});
Note: Just so I don’t get comments about it. If this was the only change you wanted to make to the page, you can and should do this purely with CSS. The idea was to add jQuery to a page in a trivial example so you can implement your own functionality later.
Deployment
To run the extension, do the following steps:
- In Chrome, Open the Browser Menu
- Click on Tools, and then Extensions
- Make sure Developer Mode is checked (usually in the top right)
- Click Load Unpacked Extension and select the folder that contains your manfiest and extension files.
That’s it! Go to any affected page and hit refresh to see your changes applied:
To get started, you can download all the files you need to run this extension from the SkyDrive folder below.
If you’ve made changes and are happy with them, you can even deploy to the Chrome Extension Store for other people to use after getting a developer account.
Here’s a couple of extensions I’ve built for chrome, along with their source code if you’re looking for examples. Feel free to leave comments on GitHub with any suggestions or bugs using GitHub’s issue tracker.
- Link Finder - Find all links to named anchors within the page so you can create descriptive links to content within a page
- Copy Tabs - Creates a keyboard shortcut (Ctrl + Shift + C) which copies links for selected tabs
Upcoming: Part 2 - How to Insert HTML, CSS, and JavaScript into any page using a browser action.
This comment has been removed by a blog administrator.
ReplyDeleteYou completed several nice points there. I did a search on the subject and found a good number of persons will consent with your blog. ipad psd
ReplyDeleteSome times its a pain in the ass to read what people wrote but this web site is very user friendly ! . website design san francisco
ReplyDeleteWe have a well-defined process and a dedicated team that will keep you well informed before every step we take. We make sure to get you the top quality website that result in more quality leads and sales. web development services in usa
ReplyDeleteIt’s really a nice and helpful piece of info. I’m glad that you just shared this helpful info with us. Please keep us informed like this. Thanks for sharing. website design company san francisco
ReplyDeleteGood website! I truly love how it is simple on my eyes and the data are well written. I am wondering how I could be notified whenever a new post has been made. I’ve subscribed to your RSS which must do the trick! Have a nice day! website design firms san francisco
ReplyDeleteThe subsequent time I read a blog, I hope that it doesnt disappoint me as a lot as this one. I imply, I do know it was my choice to learn, however I actually thought youd have something attention-grabbing to say. All I hear is a bunch of whining about something that you could repair in the event you werent too busy in search of attention. web design company san francisco
ReplyDeleteI like what you guys are up too. Such smart work and reporting! Keep up the superb works guys I have incorporated you guys to my blogroll. I think it will improve the value of my website website design firms san francisco
ReplyDeleteThanks, I have been searching for facts about this subject for ages and yours is the best I’ve discovered so far. website design company san francisco
ReplyDeleteHello! I simply wish to provide a large thumbs up for any fantastic information you could have here about this post. I will be returning to your blog site to get more soon. la web design
ReplyDeletedining room furnitures should be coated with shellac or varnish in order to preserve the wood grains:: design firms los angeles
ReplyDeleteHere is the simplest and best assistance I have ever come across on this topic. Thank you for this very helpful blog post of yours. Additionally, I enjoy writing articles which has a personal tone incorporated. I feel it makes the reader feel more important along with inclined to trust me more. Plus it appears more real rather than coming from a robot. I quite like making my viewers feel important and also special. I want to hand them over the best tips on how to deal with important issues like this. los angeles web design
ReplyDeleteI’ve been recently wondering about the exact same point myself lately. Glad to see a person on the same wavelength! Nice article. web designer la
ReplyDeleteLeaders, if you do not understand how to strengthen the building blocks in your business, you cannot grow as fast as you would like. Bluehost review
ReplyDeleteBarack understood that individual commitment would have been basic.smm panel
ReplyDeleteI am glad to be one of many visitors on this outstanding web site (:, thanks for posting . web design tips
ReplyDeleteTop post Genachowski’s less than artful weaving of net neutrality and consumer privacy | Law and Politics of Broadband you’ve surely influenced all of us FYI have you read Middle East amazing headlines! Enjoy your day ! Flash Website Design web design tips
ReplyDeleteI have wanted to write about something like this on my webpage and you gave me an idea. Cheers. website design
ReplyDeleteHave you thought about introducing some social bookmarking buttons to these blog posts. At least for facebook. branding design los angeles
ReplyDeleteIt's simpler than any time in recent memory to transfer pictures and other media through the single transfer button in the WordPress toolbar. error establishing a database connection
ReplyDeleteI recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. SEO Vancouver
ReplyDeleteI like your post. It is good to see you verbalize from the heart and clarity on this important subject can be easily observed... sydney wordpress design
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThanks, foг ones marvelous posting! I genuinely enjoyed reading it, you miggһt Ƅe a great author. I wiⅼl made certain to booҝmark your blog and ѡill often come back sometime soon. I want to encoᥙrage yourself to continue your great job, have a nice evening!
ReplyDeleteWeb Development Course
best web development courses
web development classes
web development course near me
Web Development Training
training on web development
web development training program
web development training course
web development summer training
It’s appropriate time to make some plans for the future and it is time to be happy. I have read this post and if I could I wish to suggest you few interesting things or advice. Perhaps you could write next articles referring to this article. I desire to read even more things about it! web design in Switzerland
ReplyDeleteOther private ventures work straightforwardly with bigger associations and can fill in as a gateway of passage much like the central air organization was in the Objective information break. tor hidden url list
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteIf your website is not Mobile Friendly, Google will not consider your website up to the latest standards. Yandex Scraper
ReplyDeleteWhen you stay at the head of the positioning, Internet clients will have the option to see you more.
ReplyDeleteoffpage SEO
SEO strength
SEO ranking
We are a top SEO services agency in Pakistan with a success rate of 91%. Seo Services In Pakistan
ReplyDeleteThis valuable appears to be like utterly preferred. Every single one of small to medium sized details manufactured using lots of the past becoming familiar with. I need this approach a tremendous amount. web design companies denver
ReplyDeleteIn fact your creative writing abilities has inspired me to start my own Blog Engine blog now. Really the blogging is spreading its wings rapidly. Your write up is a fine example of it samos feribot
ReplyDeleteMore often than not, everything necessary to plan your site viably is a touch of arranging. Webdesign
ReplyDeleteExcellent Blog! I would like to thank for the efforts you have made in writing this post. I am hoping the same best work from you in the future as well. I wanted to thank you for this websites! Thanks for sharing. Great websites! Webdesign
ReplyDeleteDo they follow the rules from the Google website admin? SEO lead generation
ReplyDeleteAppraisals and audits are significant proportions of a specialist's dependability and aptitude in finishing past undertakings and ought not be disregarded when settling on a consultant with whom to work.Professional graphic design
ReplyDeleteYou there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. email extractor - convert csv
ReplyDeleteThis article is an appealing wealth of useful informative that is interesting and well-written. I commend your hard work on this and thank you for this information. I know it very well that if anyone visits your blog, then he/she will surely revisit it again. free bulk mailer
ReplyDeleteIn the event that you are not a talented author, you can re-appropriate the work and have experts compose the articles for you. Regardless of whether you do this, article marketing will at present be more financially savvy when contrasted with different sorts of promoting. doctors email list
ReplyDeleteProducing ensured SEO results isn't a simple issue and SEO organizations should deal with its showcasing system and redo it to coordinate customer's necessities better. SEO Services
ReplyDeleteI’m going to read this. I’ll be sure to come back. thanks for sharing. and also This article gives the light in which we can observe the reality. this is very nice one and gives indepth information. thanks for this nice article... agence de pub
ReplyDeleteJust like most companies out there, you probably want a website that attracts more business on a regular basis and helps to attract employees as well. new business website design
ReplyDeleteBecause of this , it truly is superior you can applicable research prior to providing. It will be possible to share larger document that way. Technology
ReplyDeleteThis is essentially why they call it social media on the grounds that individuals ought to socialize with genuine individuals. Recall that in the business world, you don't simply sell your image; you additionally sell yourself and your organization. SMM Panel
ReplyDeleteThank you very much for keep this information. Unethical Medical Billing Practices
ReplyDeleteYou make so many great points here that I read your article a couple of times. Your views are in accordance with my own for the most part. This is great content for your readers. creare sito ecommerce
ReplyDeleteWe have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. sviluppo siti web
ReplyDeleteI exactly got what you mean, thanks for posting. And, I am too much happy to find this website on the world of Google. freelance content writer for hire
ReplyDeletePresently, SEOs are dealing with more customers when contrasted with the earlier years. Website laten maken
ReplyDeleteIt is likewise regular for SEO organizations to put colossal measures of the agreement into inbound connecting to compensate for the low quality of the site advancement. v
ReplyDeleteWebsite design is obviously not giving the guests with another plain bit of text. Webdesign Genk
ReplyDeleteA very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. Workmanship
ReplyDeleteFor the excellent company Begin with the internet site, the customer service over the cell phone, to the detailed care they deliver in your presence
ReplyDeleteleather jacket
I should assert barely that its astounding! The blog is informational also always fabricate amazing entitys. custom patches
ReplyDeleteI high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information? Webdesign Antwerpen
ReplyDeleteI definitely enjoying every little bit of it. It is a great website and nice share. I want to thank you. Good job! You guys do a great blog, and have some great contents. Keep up the good work. Webdesign bureau
ReplyDeleteYour website is really cool and this is a great inspiring article. Webdesign
ReplyDeleteWhen you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. Webdesign
ReplyDeleteCool you inscribe, the info is really salubrious further fascinating, I'll give you a connect to my scene. use this link
ReplyDeleteThis is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. WordPress Developer Brisbane
ReplyDeleteOnline business websites are designed to do the business needs. Webdesign-seo-limburg.be
ReplyDeleteThis is one of the most incredible blogs Ive read in a very long time.
ReplyDeletegiá vé máy bay đi đà lạt khứ hồi
từ việt nam bay sang singapore bao nhiêu tiếng
vé máy bay đi thái lan giá rẻ 2020
vé máy bay giá rẻ đi malaysia
gia ve may bay di uc
A website dispatch and fail to remember it procedure can't succeed except if your item or administration is stand-out or incredibly remarkable. In the event that you have rivalry and a one-shot web design spending plan, your rival may beat your website by continually adding new substance that gives guests motivation to return. Wat is leadgeneratie
ReplyDeleteHello, this weekend is good for me, since this time i am reading this enormous informative article here at my home.
ReplyDeletequenza app
I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. website maintenance packages
ReplyDeleteI admire this article for the well-researched content and excellent wording. I got so involved in this material that I couldn’t stop reading. I am impressed with your work and skill. Thank you so much.
ReplyDeleteJapanese Restaurant in Sandy Springs, GA
Hello, this weekend is good for me, since this time i am reading this enormous informative article here at my home.
ReplyDeleteคลินิกเสริมความงาม
I think that thanks for the valuabe information and insights you have so provided here. hire ui designer 11 best freelance
ReplyDeleteGetting affordable web design services is a crucial space in establishing a web based business. The type of internet design service you get determines your degree of success on-line because good net design companies take your curiosity into consideration in with the ability to successfully advertise your services by way of the internet. Website Security Services
ReplyDeleteThank you for some different informative blog. Wherein else may want to I am getting that kind of facts written in such an ideal approach? I have a challenge that I’m simply now operating on, and i have been on the appearance out for such records.
ReplyDeleteIdn Sports