I’m completely new to chrome extensions but I’ve read the getting started and assembled the example from Google. I would like to build an extension that while it’s active it captures middle mouse click events on mydomain.com, reads the URL , modifies it and launches the new tab with the newly created URL.
From what I understand so far I need to have a manifest.json file and a my_script.js file that will be injected in all mydomain.com page loads. Is this correct ? If yes how should I proceed next and what should I add to my manifest and javascript file to accomplish the given task. Some code examples would be much appreciated.
I’ve also read a couple of answers here on stackoverflow and if browserAction is going to be used it can only be used in extension pages, so you can not use it in content scripts. That would mean I would have to place my code in the background page instead of my_script.js . Please advice how should I proceed.
Thank you
Working script solution is:
$(document).click(function(e) {
var urlToGo = window.location.href;
// middle button
if (e.which == 2) {
urlToGo = "http://google.com";
window.open(urlToGo);
e.preventDefault();
e.stopPropagation();
}
});
You can start with my simple Chrome Extension Content Script Skeleton https://github.com/robin-drexler/Simple-Chrome-Extension-Content-Script-Skeleton, which provides a manifest and a content script, that’ll be executed on every page you visit.
Now you can go on and implement your desired feature.
Then you could either usewindow.open to open a new tab/window (easier way) or the native Chrome APIs to open a new tab.
window.open (in content script)
http://jsfiddle.net/886jY/2/
Interesting reads for Chrome APIs
Messaging between background page and content script. IIRC you can only use the CHrome Tab APIs in the background page.
http://developer.chrome.com/extensions/messaging.html
Chrome Tab API
http://developer.chrome.com/extensions/tabs.html