Is there a development tool or Chrome / Firefox extension that lets you replace the contents of a specific URL with my own custom content?
I'm not looking for a simple /etc/hosts file change, because I want to replace a URL, not just a domain.
Is there a development tool or Chrome / Firefox extension that lets you replace the contents of a specific URL with my own custom content?
I'm not looking for a simple /etc/hosts file change, because I want to replace a URL, not just a domain.
In a Chrome extension, the webRequest
API can be used to redirect URLs to a different URL. This other URL can be another online page, but also a page within your Chrome extension.
A simple example for the webRequest
API, and a list of other options can be found in this answer.
Note: If you just want to add / change something on a specific page, Content scripts may be more suitable. You can then change the content of a specific page by standard DOM methods.
In Firefox, you can use the page-mod
module of the Addon SDK to implement the Content script.
chrome.tab API will let you to make any related changes to a tab in a window.
b) Basic Chrome Extension architecture.
You can refer this Sample Extension for changing all URL's in a current tab to Google.co.in
This is a core file where we register all chrome extension content, ensure it is with all permissions.
{
"name":"Tabs Demo",
"description":"This Demonstrates Demo of Tabs",
"browser_action":{
"default_icon":"screen.png",
"default_popup":"popup.html"
},
"permissions":["tabs"],
"manifest_version":2,
"version":"1"
}
Trivial HTML file referring to a JS file to pass CSP.
<!doctype html>
<html>
<head>
<script src="popup.js"></script>
</head>
<body>
</body>
</html>
function tabsfunction() {
//fetching all tabs in window
chrome.tabs.getAllInWindow(function (tabs) {
// Iterating through tabs
for (tab in tabs) {
//Updating each tab URL to custom url
chrome.tabs.update(tabs[tab].id, {
"url": /*You can place any URL you want here*/
"https://www.google.co.in/"
}, function () {
//Call back
console.log("Completed");
});
}
});
}
//Binging a function on document events
document.addEventListener("DOMContentLoaded", tabsfunction);
Let me know if you need more information.